Skip to content

Instantly share code, notes, and snippets.

@pirxpilot
Created January 26, 2017 18:48
Show Gist options
  • Save pirxpilot/08d251ad55ce4bdef9617a285a658bce to your computer and use it in GitHub Desktop.
Save pirxpilot/08d251ad55ce4bdef9617a285a658bce to your computer and use it in GitHub Desktop.
handling exceptions thrown in onResolved
function p() {
return new Promise(function(resolve) {
setTimeout(() => resolve(5), 200);
});
}
var x = 0;
function throwSomething() {
console.log('Throwing...', ++x);
throw x;
}
function report(e) {
console.log('Caught:', e);
}
// this will make `report` catch the exception thrown in onResolved
p().then(throwSomething).catch(report);
// this won't
p().then(throwSomething, report);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment