Oracle Magazine, Nov/Dec 2017
Database Developer OPEN SOURCE ORACLE MAGAZINE NOVEMBER OCTOBER 2017 56 Unhandled promise rejection rejection id 1 Error Ouch another error node 11780 DEP0018 DeprecationWarning Unhandled promise rejections are deprecated In the future promise rejections that are not handled will terminate the Node js process with a non zero exit code Note that unhandled errors thrown in functions passed to then and catch are swallowed up and treated like rejections This means an error will be passed to the next error handler in the chain But what happens if there are no more error handlers The updated script above throws two errors on the main thread The first error is handled properly by the subsequent catch handler However there are no error handlers after the second error is thrown This resulted in an unhandled rejection and the warnings in the console Typically when code throws errors in the main thread outside of a try catch block the process is killed In the case of an unhandled rejection in a promise chain Node js creates an unhandledRejection event on the process object If theres no handler for that event youll see the UnhandledPromiseRejectionWarning text in the output According to the deprecation warning unhandled promise rejections will kill the process in the future The solution is simple enough be sure to handle those rejections EXECUTING A QUERY WITH PROMISES Heres a practical example that demonstrates how promises can be used to execute a query As in my previous article this is a three step process that must be done serially
You must have JavaScript enabled to view digital editions.