Skip to content

Instantly share code, notes, and snippets.

@samartioli
Created November 7, 2017 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samartioli/0da3e47bc69631732b944121826710cf to your computer and use it in GitHub Desktop.
Save samartioli/0da3e47bc69631732b944121826710cf to your computer and use it in GitHub Desktop.
function test() {
return new Promise(function(resolveA, rejectA) {
// return rejectA('rejectA');
return resolveA('resolveA');
})
.then(function(results) {
return new Promise(function(resolveB, rejectB) {
return rejectB('rejectB');
// return resolveB('resolveB');
});
})
.catch(error => {
console.error('catchA: ' + error);
throw error;
});
};
test()
.then(function(results) {
return console.log(results);
})
.catch(error => {
console.error('catchTop: ' + error);
});
@samartioli
Copy link
Author

Using a .catch within a promise chain will terminate the propagation unless you throw an error in the catch.
So as the code is above, the output will be

catchA: rejectB
catchTop: rejectB

If you comment out line 18, you only get: catchA: rejectB

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