Created
January 26, 2017 18:48
-
-
Save pirxpilot/08d251ad55ce4bdef9617a285a658bce to your computer and use it in GitHub Desktop.
handling exceptions thrown in onResolved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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