The 5 commandments of clean error handling in TypeScript

<p>Dealing with errors is an essential part of software engineering.</p> <p>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!</p> <p>At Orus (where we try to&nbsp;<a href="https://www.orus.eu/" rel="noopener ugc nofollow" target="_blank">reinvent professional insurance</a>), over time, we tailored an error strategy that works well for us and that we think could be useful to share.</p> <p>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.</p> <p>Without further ado, here are our 5 error handling commandments:</p> <ul> <li><strong><em>#1</em>: Make sure Errors are, well&hellip; Errors</strong></li> <li><strong><em>#2</em>: Don&rsquo;t lose your stack trace</strong></li> <li><strong><em>#3</em>: Use constant error messages</strong></li> <li><strong><em>#4</em>: Provide the right amount of context</strong></li> <li><strong><em>#5</em>: Don&rsquo;t throw errors for problems that are expected to happen</strong></li> </ul> <p>Did this peak your interest? If so,&nbsp;<strong>read on!</strong></p> <p><a href="https://medium.com/with-orus/the-5-commandments-of-clean-error-handling-in-typescript-93a9cbdf1af5">Visit Now</a></p>