Error Handling
Part of the Go course
You have already typed if err != nil more than once in this course without stopping to ask what err actually is or where it comes from. Functions fail all the time in ordinary, expected ways: a file the caller asked for is not on disk, a number the caller supplied is out of range, a division has a zero on the bottom.
You met interfaces in the last lesson as a list of method signatures that any type can satisfy just by having the right methods, with no declaration linking the two. error is the simplest possible example of that idea, built right into the language:
Want to learn Go Error Handling in a real environment?
Click below, get a fresh Linux box with Go ready to go, and work through Error Handling hands-on with an AI tutor that knows your code.
Start this lessonError HandlingWhat you'll learn
- Error interface
- Fmt.Errorf with %w
- Errors.Is
- Errors.As
- Custom error types
- Panic vs error
- Wrapping context into errors
