Skip to content

Instantly share code, notes, and snippets.

@chvonrohr
Created June 14, 2019 14:06
Show Gist options
  • Save chvonrohr/b10fdfd1c02567361d36780ef8b23d8b to your computer and use it in GitHub Desktop.
Save chvonrohr/b10fdfd1c02567361d36780ef8b23d8b to your computer and use it in GitHub Desktop.
try-catch - functional programming
export function tryCatch({
tryer,
catcher
}) {
return (props) => {
try {
return tryer(props);
} catch (e) {
return catcher(props, e.message);
}
};
}
@chvonrohr
Copy link
Author

tryCatch({
  tryer: (param) => {
    // try something
    return true;
  },
  catcher: (e) => {
     // clean up
    return false;
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment