How do you recover from a promise rejection in JavaScript?
Return a value from .catch. The chain continues as fulfilled with that value: .catch(err => 'fallback').then(result => render(result)). The .then receives 'fallback'.
Explore This Question
Search for additional explanations using these tools:
More FAQs in Promise Error Handling With .catch in JavaScript
It handles rejections from the original promise and thrown errors from any .then above it. .catch receives the error. After .catch, the chain continues with the returned value (recovery).
Yes. .catch catches both rejections from the original promise and errors thrown in any .then callback above it. This is why .catch is better than .then's second argument, which only catches rejections from the original promise.
A promise that rejects but has no .catch (or try/catch with async/await). In Node.js, this can crash the process. In browsers, it is a warning. Always handle errors to avoid unhandled rejections.
Still have questions?
Browse all our FAQs or reach out to our support team
