Facebook Pixel

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'.

Verify This Answer

Cross-check this information using these trusted sources:

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

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.