Skip to content

Instantly share code, notes, and snippets.

@domenic
Last active May 18, 2016 21:00
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 domenic/c64aec5b1ff5ce0a6a9edc896dbd1418 to your computer and use it in GitHub Desktop.
Save domenic/c64aec5b1ff5ce0a6a9edc896dbd1418 to your computer and use it in GitHub Desktop.
catch cancel
// 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;
}
}
}
}
}
// 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