Three Ways to Handle Exceptions with Async Functions

Javascript exceptions shouldn’t be thrown when an IO  to error occurs. Instead, helpful messages should be sent your your logger system AND to the user.

Method 1: Try/Catch

Traditionally, these exceptions are handled using Try/Catch blocks, but those can easily make your code unreadable. For example,

Method 2: Catch Callback

Method 3: Custom Exception Wrapper

This method is inspired by Dima Grossman’s post.

Which to Choose?

Method 1 is just plain yuck. Method 2 is decent, I prefer Method 3 for readability.

Comments are closed.