Skip to content

Instantly share code, notes, and snippets.

@starovoitovs
Created February 16, 2018 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starovoitovs/e73fcfdeee9b36b7ab93cc21ab7e2bb1 to your computer and use it in GitHub Desktop.
Save starovoitovs/e73fcfdeee9b36b7ab93cc21ab7e2bb1 to your computer and use it in GitHub Desktop.
Try / catch expression
const xtry = (xtry, xcatch, xfinally) => {
try {return xtry()} catch (e) {return xcatch && xcatch()} finally {xfinally && xfinally()}
}
// undefined
xtry(() => {throw new Error})
// default
xtry(() => {throw new Error}, () => "default")
// optional
xtry(() => "optional", () => "default")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment