Created
September 18, 2016 10:36
-
-
Save sairion/41e44878cc3d1d5269aa18e87d7061a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Promise exception handling is actually handled by mulitple level - therfore you need to care about many things | |
new Promise((res, rej) => { | |
setTimeout(_ => { | |
// case 1) error outside of promise context | |
res('booom 2'); | |
throw new Error('error 2'); // this won't get ignored like case 1 and have to be catched manually. Also this don't automatically goes to `onRejected` handler unlike case 1. | |
}, 3000); | |
// case 2) | |
// res('booom 1'); | |
// throw new Error('error 1'); // This gets ignored because it is thrown after resolve function gets called. | |
}) | |
.then(function onFulfilled(res) { | |
throw new Error('error in onFulfilled'); // This error will be catched and handled by to catch();, if fulfilled. | |
console.debug('fulfilled', res); | |
}, function onRejected(res) { | |
throw new Error('error in onRejected'); | |
console.debug('rejected', res); | |
}) | |
.catch(err => { | |
console.debug('Caught error from catch()', err) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment