Error Handling in Go

Mastering pragmatic error handling in your Go code


result can’t be trusted before checking for errors
The blank identifier is dark and full of terrors.

Under the hood

The error Interface

error interface from the source code

The built-in errorString struct

source: Go source code
try it

Working with Errors

Type Assertion

playground: short syntax panic, safe long syntax

Asserting with interface type T

source: pkg/errors

Asserting with concrete type T & Type Switches

Wrapping up

What’s next?

Back End Developer and Golang Enthusiast. I am a sucker for great code, and I like to hack whatever comes my way.