DEV Community


Discussion on: Errors Are Not Exceptions

loujaybee profile image
Lou — Cloud Engineer

A nice article! Thanks for writing up!

My approach to error handling in JS I detailed here:

But the TL;DR: is:

  • Wrap all behavior into a try/catch
  • Wrap any nested code into a try/catch where you think necessary, and throw an explicit error for things which you're handling
  • Anything that comes through as an unhandled exception then becomes a ticket, and the error handling is put in place to ensure the unhandled exception is put in place.

Doing this means you never miss any unhandled errors, and gives a very clear pattern for error handling in JS.

But... I prefer go's way of doing things, which becomes essentially the same, but without the high level try/catch boilerplate, etc.