Created
February 16, 2018 10:11
-
-
Save starovoitovs/e73fcfdeee9b36b7ab93cc21ab7e2bb1 to your computer and use it in GitHub Desktop.
Try / catch expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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