Skip to content

Instantly share code, notes, and snippets.

@tlivings
Last active December 27, 2015 15:39
Show Gist options
  • Select an option

  • Save tlivings/7349274 to your computer and use it in GitHub Desktop.

Select an option

Save tlivings/7349274 to your computer and use it in GitHub Desktop.
Try catch utility so optimization still occurs in the calling function. lol?
'use strict';
function attempt(fn) {
return Object.create({
'fail': function (onError) {
try {
fn();
}
catch (e) {
return onError(e);
}
}
});
}
exports = module.exports = attempt;

Example:

attempt(function () {
    JSON.parse();
}).
fail(function (e) {
    console.error(e);
});
@totherik
Copy link
Copy Markdown

totherik commented Nov 7, 2013

Either way, I think it's worth trying out if it helps inlining.

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