<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Chapter 7 Error Handling on Go: Under the Hood</title><link>https://golang.design/under-the-hood/en/part2lang/ch07errors/</link><description>Recent content in Chapter 7 Error Handling on Go: Under the Hood</description><generator>Hugo</generator><language>en</language><atom:link href="https://golang.design/under-the-hood/en/part2lang/ch07errors/index.xml" rel="self" type="application/rss+xml"/><item><title>7.1 The Evolution of the Problem</title><link>https://golang.design/under-the-hood/en/part2lang/ch07errors/value/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://golang.design/under-the-hood/en/part2lang/ch07errors/value/</guid><description>&lt;h1 id="71-the-evolution-of-the-problem"&gt;7.1 The Evolution of the Problem&lt;/h1&gt;
&lt;p&gt;In &lt;a href="../../ch06func/panic"&gt;6.3&lt;/a&gt; we already drew the dividing line: how to handle errors is one of the
fundamental choices in language design. The exception camp (C++, Java, Python) uses &lt;code&gt;try/catch&lt;/code&gt; to
pull the error path out of the normal logic, keeping the main line clean, at the cost of making the
error path implicit, capable of being thrown from any call site. The value camp (Go, Rust, and C&amp;rsquo;s
return-code tradition) passes errors explicitly as ordinary return values: verbose, but every error
path is spelled out in black and white with nowhere to hide. Go chose the value camp, reserving a
lightweight &lt;code&gt;panic&lt;/code&gt;/&lt;code&gt;recover&lt;/code&gt; only for &amp;ldquo;true exceptions.&amp;rdquo; What this section is about is what happened
after that choice landed: how the proposition of &amp;ldquo;errors as values&amp;rdquo; itself evolved, from a string you
could only print into a tree that a program can interrogate layer by layer, asking &amp;ldquo;are you really
that error?&amp;rdquo;&lt;/p&gt;</description></item><item><title>7.2 Inspecting Error Values</title><link>https://golang.design/under-the-hood/en/part2lang/ch07errors/inspect/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://golang.design/under-the-hood/en/part2lang/ch07errors/inspect/</guid><description>&lt;h1 id="72-inspecting-error-values"&gt;7.2 Inspecting Error Values&lt;/h1&gt;
&lt;p&gt;Once an error propagates up a call chain, the code that handles it and the code that produced it
are often separated by many layers. This raises a plain but thorny question: given an &lt;code&gt;error&lt;/code&gt; that
has been passed up through layer after layer, how does the caller decide &amp;ldquo;is this actually some
particular error&amp;rdquo;, and how does it retrieve the specific error value that originally carried the
context? This section answers exactly that, along with the conventions Go has set down for it in
the &lt;code&gt;errors&lt;/code&gt; package.&lt;/p&gt;</description></item><item><title>7.3 Error Format and Context</title><link>https://golang.design/under-the-hood/en/part2lang/ch07errors/context/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://golang.design/under-the-hood/en/part2lang/ch07errors/context/</guid><description>&lt;h1 id="73-error-format-and-context"&gt;7.3 Error Format and Context&lt;/h1&gt;
&lt;p&gt;A good error does not merely say &amp;ldquo;something went wrong.&amp;rdquo; It tells a person what was being done, on account of what, and what went wrong. The evolution of the problem (&lt;a href=".././value"&gt;7.1&lt;/a&gt;) and value inspection (&lt;a href=".././inspect"&gt;7.2&lt;/a&gt;) gave us the mechanisms for propagating and examining errors. This section discusses the engineering practice that sits on top of those mechanisms: how the text of an error should be written, how context accumulates layer by layer along the call chain, and how stack traces and structured logs can be added on demand when human-written words are not enough. Running through all of it is one overall tendency Go has regarding error information: human-written semantic context is preferable to machine-collected stack traces.&lt;/p&gt;</description></item><item><title>7.4 Error Semantics</title><link>https://golang.design/under-the-hood/en/part2lang/ch07errors/semantics/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://golang.design/under-the-hood/en/part2lang/ch07errors/semantics/</guid><description>&lt;h1 id="74-error-semantics"&gt;7.4 Error Semantics&lt;/h1&gt;
&lt;p&gt;&lt;a href=".././inspect"&gt;7.2&lt;/a&gt; and &lt;a href=".././context"&gt;7.3&lt;/a&gt; stood on the caller&amp;rsquo;s side of an error and worked out how, once
you hold an &lt;code&gt;error&lt;/code&gt;, to inspect it along the chain and how to layer context onto it. This section turns the
viewpoint to the other side, standing with the library author and asking a question that comes before
inspection: when a package wants to expose a failure to the outside world, what &lt;strong&gt;form&lt;/strong&gt; should it give that
error? Should it export a comparable value, export a type with fields, or export nothing at all?&lt;/p&gt;</description></item><item><title>7.5 The Future of Error Handling</title><link>https://golang.design/under-the-hood/en/part2lang/ch07errors/future/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://golang.design/under-the-hood/en/part2lang/ch07errors/future/</guid><description>&lt;h1 id="75-the-future-of-error-handling"&gt;7.5 The Future of Error Handling&lt;/h1&gt;
&lt;p&gt;In the preceding sections we saw the plainness of the &lt;code&gt;error&lt;/code&gt; interface, &lt;code&gt;%w&lt;/code&gt; wrapping, and the inspection of error chains. By this point the reader probably carries an unspoken question: those three lines of &lt;code&gt;if err != nil&lt;/code&gt; boilerplate, spread year after year across every Go program, is there really no way to get rid of them? The question is not a lonely one. From the go2 draft of 2018 to a single conclusion in 2025, the Go team weighed it back and forth for seven years, proposing several syntaxes such as &lt;code&gt;check&lt;/code&gt;/&lt;code&gt;handle&lt;/code&gt;, &lt;code&gt;try&lt;/code&gt;, and &lt;code&gt;?&lt;/code&gt;, and then withdrawing them one by one. This section places that path of failed syntax side by side with another, quietly successful path of library evolution, and lays out the judgment the Go team finally arrived at: for the foreseeable future, error handling will not receive any dedicated syntax.&lt;/p&gt;</description></item></channel></rss>