Facebook Pixel
Promise .then, .catch, and .finally Explained

Can you recover from a promise rejection in JavaScript?

The answer

Yes. Return a value from .catch, and the chain continues with that value: .catch(err => 'fallback').then(result => render(result)). The .then receives 'fallback' instead of the error.

More FAQs in Promise .then, .catch, and .finally Explained

.then runs when the promise fulfills (receives the value). .catch runs when the promise rejects or a .then throws (receives the error). .finally runs when the promise settles, regardless of outcome (no value or error received).

Yes. Each .then (and .catch and .finally) returns a new promise. If the callback returns a value, the new promise fulfills with that value. If it returns a promise, the new promise waits for it. This enables chaining.

If a .then callback throws, the error skips subsequent .then callbacks and propagates to the next .catch. If there is no .catch, the error becomes an unhandled rejection. After .catch, the chain continues with the value returned by .catch.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

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

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.