Section 5 of 11
Errors are values
No exceptions, no stack unwinding. You return errors and the caller checks them.
error is an ordinary interface with one method. Nothing is thrown and nothing is caught. The verbosity is the point: every failure path is visible at the call site instead of hidden in a signature.
Wrapping, errors.Is, errors.As
go.dev playground
Try it: Swap %w for %v in the fmt.Errorf and watch errors.Is stop matching — %w is what preserves the chain.
- if err != nil { return err } is the whole idiom. Wrap with fmt.Errorf("doing x: %w", err) to add context.
- errors.Is compares against a sentinel; errors.As extracts a concrete error type.
- panic exists but is for programmer bugs (index out of range, nil deref), not control flow.
- recover() in a deferred function stops a panic — used at goroutine boundaries in servers, and almost nowhere else.