Stage 1 · Lesson 3 of 10
Errors as values
Go has no exceptions for ordinary failures. Instead, Go treats . A function that can fail returns an error as its last value, and the caller checks if err != nil straight away.
As an error travels up, wrap it with context using fmt.Errorf("load order %d: %w", id, err). Inspect it later with errors.Is and errors.As. For example, you can spot sql.ErrNoRows and turn it into a .
Use defer to close files and connections when a function ends. Save panic for truly unrecoverable bugs. The explicit checks feel wordy at first, but they make every failure path visible.
Common trapignoring an error with _ or returning it with no context, which leaves "connection refused" in the logs and no idea where it came from.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with
- CourseFreeA Tour of Go
The Go Authors · Beginner
The official interactive tour: basics, methods, interfaces, generics and concurrency
Practise
Keep handy
Also worth your time
The DNS, TCP, TLS and HTTP steps behind every request your backend will handle