Last active
May 18, 2016 21:00
-
-
Save domenic/c64aec5b1ff5ce0a6a9edc896dbd1418 to your computer and use it in GitHub Desktop.
catch cancel
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
// This does not work at all, for unknown reasons: | |
let catch = macro { | |
case { | |
try { | |
$tryBody ... | |
} $name ($exception:ident) { | |
$catchBody ... | |
} | |
} => { | |
return #{ | |
try { | |
$tryBody ... | |
} catch ($exception) { | |
if (!$exception || !Object.prototype.hasOwnProperty.call($exception, "__throwCancel")) { | |
$catchBody ... | |
} else { | |
throw $exception; | |
} | |
} | |
} | |
} | |
} | |
// This works, but also catches the case of class C { foo() {} catch(e) {} }: | |
let catch = macro { | |
case { | |
$name ($exception:ident) { | |
$catchBody ... | |
} | |
} => { | |
return #{ | |
catch ($exception) { | |
if (!$exception || !Object.prototype.hasOwnProperty.call($exception, "__throwCancel")) { | |
$catchBody ... | |
} else { | |
throw $exception; | |
} | |
} | |
} | |
} | |
} |
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
// Want to transform this: | |
try { | |
a(); | |
} catch (e) { | |
b(e); | |
} | |
// Do NOT want to transform this: | |
class C { | |
foo() { | |
} | |
catch(e) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment