The 5 commandments of clean error handling in TypeScript

Dealing with errors is an essential part of software engineering.

Defining and having strong guidelines on how to handle errors will make your life easier when developing features, but also, and maybe more importantly when things go wrong!

At Orus (where we try to reinvent professional insurance), over time, we tailored an error strategy that works well for us and that we think could be useful to share.

While this post is mainly dedicated to error handling in TypeScript, some of the principles that we will go through are quite general and applicable to other languages as well.

Without further ado, here are our 5 error handling commandments:

  • #1: Make sure Errors are, well… Errors
  • #2: Don’t lose your stack trace
  • #3: Use constant error messages
  • #4: Provide the right amount of context
  • #5: Don’t throw errors for problems that are expected to happen

Did this peak your interest? If so, read on!

Visit Now