<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Error-Handling on Momori Nakano</title><link>https://momori.dev/tags/error-handling/</link><description>Recent content in Error-Handling on Momori Nakano</description><generator>Hugo -- 0.147.0</generator><language>en-us</language><lastBuildDate>Tue, 06 Feb 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://momori.dev/tags/error-handling/index.xml" rel="self" type="application/rss+xml"/><item><title>Rust Error Handling: thiserror, anyhow, and When to Use Each</title><link>https://momori.dev/posts/rust-error-handling-thiserror-anyhow/</link><pubDate>Tue, 06 Feb 2024 00:00:00 +0000</pubDate><guid>https://momori.dev/posts/rust-error-handling-thiserror-anyhow/</guid><description>&lt;p>In this blog post, we&amp;rsquo;ll explore strategies for streamlining error handling in Rust using two popular libraries: &lt;a href="https://docs.rs/thiserror/latest/thiserror/">thiserror&lt;/a> and &lt;a href="https://docs.rs/anyhow/latest/anyhow/">anyhow&lt;/a>. We&amp;rsquo;ll discuss their features, use cases, and provide insights on when to choose each library.&lt;/p>
&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;ul>
&lt;li>&lt;code>thiserror&lt;/code> simplifies the implementation of custom error type, removing boilerplates&lt;/li>
&lt;li>&lt;code>anyhow&lt;/code> consolidates errors that implement &lt;code>std::error::Error&lt;/code>&lt;/li>
&lt;li>While &lt;code>thiserror&lt;/code> provides detailed error information for specific reactions, &lt;code>anyhow&lt;/code> hides internal details&lt;/li>
&lt;/ul>
&lt;h2 id="return-different-error-types-from-function">Return Different Error Types from Function&lt;/h2>
&lt;p>Let&amp;rsquo;s start by creating a function &lt;code>decode()&lt;/code> for illustration. The function has 3 steps:&lt;/p></description></item></channel></rss>