Get the latest tech news

Why Go's Error Handling Is Awesome


famous error handling has caught quite the attention from outsiders to the programming language, often touted as one of the language's most questionable design decisions. If you look into any project on Github written in Go, it's almost a guarantee you'll see the lines more frequently than anything else in the codebase: if err != nil { return err } Although it may seem redundant and unnecessary for those new to the language, the reason errors in Go are treated as first-class citizens (values) has a deeply-rooted history in programming language theory and the main goal of Go as a language itself.

No hidden control-flows No unexpected uncaught exception logs blowing up your terminal (aside from actual program crashes via panics) full-control of errors in your code as values you can handle, return, and do anything you want with Rust, for example, has a good compromise of using option types and pattern matching to find error conditions, leveraging some nice syntactic sugar to achieve similar results. Perhaps the difference between making the code above become aware of exceptions is to switch the order of saveToDB(item) and item.Text = 'price changed, which is opaque, hard to reason about, and can encourage some lazy programming habits.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of error handling

error handling

Related news:

News photo

How we centralized and structured error handling in Golang

News photo

The Ultimate Guide to Error Handling in Python

News photo

Guide to Error Handling in Rust