Exception Handling
We've been over how to turn then
chaining into await
, but what about catch
? If a promise is rejected, the error will bubble up and must be caught in some way. Failing to catch an exception in the async
/await
world is just as damaging as failing to catch a promise rejection. In fact, it's exactly the same and async
/await
is just syntactic sugar on top of promises.
Failing to handle a rejected promise can lead to system failure where a program running in a web browser crashes, resulting in blank pages or broken functionality, thereby driving users away from your site. A failure to handle a rejected promise on the server side may cause a Node.js process to exit and a server to crash. Even if you have a self-healing system that attempts to bring your server back online, whatever job you were attempting to complete will have failed and frequently repeated restarts will make your infrastructure more expensive to run.
The most straightforward way to handle...