Skip to content

Instantly share code, notes, and snippets.

@poying
Last active September 16, 2015 10:55
Show Gist options
  • Save poying/5055079f1976c1c36d29 to your computer and use it in GitHub Desktop.
Save poying/5055079f1976c1c36d29 to your computer and use it in GitHub Desktop.
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