Created
November 7, 2017 20:20
-
-
Save samartioli/0da3e47bc69631732b944121826710cf to your computer and use it in GitHub Desktop.
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 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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
If you comment out line 18, you only get:
catchA: rejectB