Skip to content

Instantly share code, notes, and snippets.

@poying
Last active September 16, 2015 10:55
Embed
What would you like to do?
let _try_catch = macro {
rule { catch ($e:ident) { $body ...} } => {
{
let $e = __e;
$body ...
return;
}
}
rule { catch ($e:ident if $c:expr) { $body ...} } => {
{
let $e = __e;
if ($c) {
$body ...
return;
}
}
}
}
let try = macro {
rule { { $body ...} $c:_try_catch ... } => {
try {
$body ...
} catch (__e) {
(function () {
'use strict';
$c ...
})();
}
}
}
@poying
Copy link
Author

poying commented Sep 16, 2015

try {
  // ...
} catch (e if e instanceof TypeError) {
  // ...
} catch (e) {
  // ...
}

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