Say you have a promise chain like this:
asyncFunction()
.then((value) => {
resolve(value)
})
.then((value) => {
resolve(value)
})
.then((value) => {
resolve(value)
})
.catch((error) => {
reject(error)
})
If an error is thrown during one of those function calls, does that error automatically propagate all the way down to the catch
at the end of the chain? Say the error is thrown at the beginning, during asyncFunction()
, what are the exact mechanics of how it propagates? Is the error passed to the handler of each then
? Or does each then look for a second handler, not see one, and so pass the error to the next then
?
Yes, it will get propagated down until it hits the first catch
. All then
clauses should be skipped.
I noticed the use of resolve()
and reject()
avoid this, there's no need for the Promise constructor pattern in case like this.