Posted by: K. Scott Allen,
on 01 Oct 2015 |
View original | Bookmarked: 0 time(s)
Errors in asynchronous code typically require a messy number of if else checks and a careful inspection of parameter values. Promises allow asynchronous code to apply structured error handling. When using promises, you can pass an error handler to the then method or use a catch method to process errors. Just like exceptions in regular code, an exception or rejection in asynchronous code will jump to the nearest error handler. As an example, lets use the following functions which log the execution...