Module 04 Β· Interfaces & Errors β Lesson 3 of 3 Β· ~9 min
Error handling patterns
The idiom you'll type a thousand times
Because errors are values, handling them is just an if. The Go program is dotted with this exact block:
result, err := doSomething()
if err != nil {
return result, err
}It looks repetitive, and it is β deliberately. Every failure is visible at the point it happens; nothing is hidden in an invisible throw. Reading a Go function top to bottom, you see every place it can bail out. That explicitness is the trade Go makes on purpose.