Technical Mid Level

Go does not have exceptions. How do you structure error handling in a Go application? What are your views on error wrapping and sentinel errors?

Quick Tip

Show a clear philosophy: "I wrap errors with context at each layer using fmt.Errorf with %w, define sentinel errors for expected conditions callers need to handle, and never use panic for normal error paths."

What good answers include

Go uses explicit error return values. Strong candidates discuss: wrapping errors with fmt.Errorf and %w for context while preserving the chain, using errors.Is() and errors.As() to inspect wrapped errors, defining sentinel errors (var ErrNotFound = errors.New(...)) for expected conditions, and custom error types for rich error information. They should mention that panic is reserved for truly unrecoverable situations, not control flow.

What interviewers are looking for

Fundamental Go pattern. Candidates who find error handling tedious and try to work around it (empty error checks, panic-recover for flow control) will write unreliable code. Look for disciplined, consistent error handling with proper context.

← All Go questions