Promise .catch(): Handling Rejections

`.catch()` is the `try...catch` for promises, intercepting errors (rejections) in a chain. Use it at the end of a promise chain to handle failures from preceding steps, like a failed API call. The footgun: placing it mid-chain can swallow errors.
Think of `.catch()` as the dedicated error lane for promises. It intercepts any rejection from an upstream promise, letting you handle failures gracefully. It's essential for robust async code, like catching a failed API call in a `fetch` chain. Because it returns a new promise, the chain can continue. The biggest footgun is placing it mid-chain; it handles the error, but subsequent `.then()` blocks run as if the operation succeeded, often with undefined data.
Read the original → developer.mozilla.org
- #javascript
- #promises
- #asynchronous
- #error handling
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.