O'Reilly logo

JavaScript Promises Essentials by Rami Sarieddine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling errors with promises

As we have seen, promises offer a richer error handling mechanism in asynchronous programming. Although the Promises/A+ spec tackles only one method, that is .then(onFulfilled, onRejected), and does not provide any other, the specifications of .then() lay the foundation for promise interoperability and, hence, extend the promise features, including error handling.

We might come across several implementations for error handling within JavaScript libraries that are compatible with Promises/A+. Some of these extensions include the catch() method, which is implemented on top of the elementary then() function. Anyone can author a catch() method and include it in their scripts by extending the promise object as per the following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required