JS Built-ins
AsyncPatternsadvanced

.catch after .then is a Promise

πŸ“– Usage Example
const safe = Promise.reject('err')
  .then(v => v)
  .catch(e => 'caught: ' + e);
// resolves to 'caught: err'

.catch chained after .then still catches rejections from earlier in the chain.

Promise Chain

Chaining .then() and .catch() creates a chain of Promises.

Challenge: Verify that .catch() after .then() returns a Promise.

πŸ’‘ Hints (3)
  • β€’ Each .then(), .catch(), and .finally() returns a new Promise.
  • β€’ Promises can be chained indefinitely.
  • β€’ Error handlers in the chain can recover from errors.