<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cesar Marcano</title>
    <description>The latest articles on DEV Community by Cesar Marcano (@sircesarium).</description>
    <link>https://dev.to/sircesarium</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3925742%2F3d91bb22-3b36-4320-8cb6-5c90960fb602.jpeg</url>
      <title>DEV Community: Cesar Marcano</title>
      <link>https://dev.to/sircesarium</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sircesarium"/>
    <language>en</language>
    <item>
      <title>Rest In Peace, Throw: TypeScript error handling 22x faster in just 1.6KB</title>
      <dc:creator>Cesar Marcano</dc:creator>
      <pubDate>Tue, 12 May 2026 04:53:55 +0000</pubDate>
      <link>https://dev.to/sircesarium/rest-in-peace-throw-typescript-error-handling-22x-faster-in-just-16kb-43f6</link>
      <guid>https://dev.to/sircesarium/rest-in-peace-throw-typescript-error-handling-22x-faster-in-just-16kb-43f6</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtrci8dk4c5mp3mvmsep.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtrci8dk4c5mp3mvmsep.png" alt="Example code using ripthrow" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In TypeScript, we’ve been told that &lt;code&gt;try/catch&lt;/code&gt; is the standard for error handling. But there’s a catch: &lt;strong&gt;native exceptions are essentially invisible GOTO statements&lt;/strong&gt; that jump over layers of your application, making it incredibly hard to reason about state.&lt;/p&gt;

&lt;p&gt;Even worse, because JavaScript allows you to throw anything (from strings to dates), TypeScript is forced to treat every caught error as &lt;code&gt;unknown&lt;/code&gt;. This creates a &lt;strong&gt;type-erasure effect&lt;/strong&gt; where your function's failure states become invisible to the compiler and uncontracted in your signatures.&lt;/p&gt;

&lt;p&gt;I built &lt;strong&gt;ripthrow&lt;/strong&gt; to fix this. It’s a 1.6KB, zero-dependency library that brings Rust-inspired error handling to TypeScript with a focus on pragmatism and raw performance.&lt;/p&gt;

&lt;h4&gt;
  
  
  22x Performance over native &lt;code&gt;throw&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Most people don't realize how expensive &lt;code&gt;throw&lt;/code&gt; actually is. Based on my benchmarks (running on Bun 1.3), the difference is staggering:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Operations/sec&lt;/th&gt;
&lt;th&gt;Latency&lt;/th&gt;
&lt;th&gt;vs Native&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Err() (ripthrow)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;25,357,831&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;41.6 ns&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;throw (Native)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1,182,517&lt;/td&gt;
&lt;td&gt;1047.0 ns&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;22x slower&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;By returning a &lt;code&gt;Result&lt;/code&gt; instead of throwing, you get the same speed as a manual object literal because &lt;strong&gt;ripthrow uses POJOs (Plain Old JavaScript Objects)&lt;/strong&gt; instead of expensive class allocations. In real-world scenarios, the overhead is a negligible 15-20 ns per operation.&lt;/p&gt;

&lt;h4&gt;
  
  
  How it looks in practice
&lt;/h4&gt;

&lt;p&gt;Stop nesting &lt;code&gt;if&lt;/code&gt; statements and losing your types. With the &lt;code&gt;AsyncResultBuilder&lt;/code&gt;, you can create fluent pipelines that are 100% type-safe:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Errors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createErrors&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;UserNotFound&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`User #&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; not found`&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getUserName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Wrap promises safely without try/catch blocks&lt;/span&gt;
  &lt;span class="c1"&gt;// Note: ripthrow offers multiple wrapping strategies; see the GitHub Wiki for details.&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;AsyncResultBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;safeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mapErr&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UserNotFound&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getUserName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hi! &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Fully typed success&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "User #123 not found"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Exhaustive Matching
&lt;/h4&gt;

&lt;p&gt;One of the biggest risks of manual error handling is forgetting a case. While other libraries require manual &lt;code&gt;switch&lt;/code&gt; statements or &lt;code&gt;never&lt;/code&gt; checks, &lt;strong&gt;ripthrow&lt;/strong&gt; has a built-in fluent API for this.&lt;/p&gt;

&lt;p&gt;If you add a new error type to your application and forget to handle it, &lt;strong&gt;your code won't compile&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This will throw a type error at compile-time if 'NetworkError' is not handled&lt;/span&gt;
&lt;span class="c1"&gt;// Note: defining explicit `data: User` type is required to ensure that you're handling all the errors&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;matchErr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;UserNotFound&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;...)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exhaustive&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Why ripthrow?
&lt;/h4&gt;

&lt;p&gt;While other libraries exist, &lt;strong&gt;ripthrow&lt;/strong&gt; is designed as a "missing operator" for modern ESM:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Minimalist:&lt;/strong&gt; Only ~1.6 KB (min+gzip).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;No Classes:&lt;/strong&gt; Uses simple &lt;code&gt;{ ok: true, value }&lt;/code&gt; structures for maximum speed.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Exhaustive Matching:&lt;/strong&gt; Use &lt;code&gt;.exhaustive()&lt;/code&gt; to ensure at compile-time that you’ve handled every possible error variant.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Collision-Free:&lt;/strong&gt; Unique Symbols identify error types, preventing collisions between different packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to make your TypeScript applications more resilient and faster, &lt;strong&gt;ripthrow&lt;/strong&gt; is now at &lt;strong&gt;v3.0 - Stable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Check it out on GitHub: &lt;a href="https://github.com/MechanicalLabs/ripthrow" rel="noopener noreferrer"&gt;MechanicalLabs/ripthrow&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>performance</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
