JS: Promise .prototype .catch
Promise .prototype .catch
syntax:
promise_object.catch(ferr)
ferr is a function that takes one arg.
when the promise_object is rejected, ferr is called with an arg xerror, where xerror is the arg passed to reject function in the promise f_executor function body.
What's the difference between p.then(aa, bb) vs p.then(aa).catch(cc)
bb (the second argument of .then) only sees a rejection of p itself.
If aa throws, or returns a rejected promise, bb does not run. That rejection goes to whatever comes after this .then.
.catch sits after aa, so it sees:
- rejection of
p - a throw inside
aa - a rejected promise returned by
aa