then (..) takes one or two parameters, the first for the callback to execute, and the second for the failure callback. If passed or otherwise passed as a non-functional value, the default callback is replaced accordingly. The default execution callback simply passes the message together, while the default rejection callback simply retells (propagates) the cause of the error it receives. catch (..) only accepts the reject callback as a parameter and automatically replaces the default execution callback as just discussed. In other words, its equivalent is then (null, ...):
p . then ( fulfilled ); p . then ( fulfilled , rejected ); p . catch ( rejected ); // or `p.then( null, rejected )`
then (..) and catch (..) also create and return a new promise that can be used to express Promise chain flow control. If the execution or rejection of the callback has an exception, the returned promise is rejected. If either the callback returns an immediate, not a promise, non-thenable value, this value is set as execution for the returned promise. If the execution handler specifically returns a promise or a subsequent value, this value is unpacked and the resolution of the promised promise becomes.
- From "Don't Know Jace", Kyle Simpson
source share