Module 05 of 12

Error Handling

Lessons

About This Module

Go treats errors as ordinary values rather than exceptions. A function that can fail returns an error, and the caller decides what to do with it. This makes failure paths explicit and easy to follow, and it is one of the first things that makes Go code feel different.

This module starts with basic errors and the standard checking pattern. It then covers creating, wrapping and custom errors, how the errors package helps you inspect them, and finally defer, panic and recover, for the rare cases where a program cannot simply return an error.

Watch the lessons in order and practice by adding proper error checks to your own small programs, then continue on to Packages, Modules & Generics.

Lessons

4 videos
01

Basic Errors in Go

The starting point: how Go represents errors, how functions return them, and how to check them in your own code.

02

Error Handling: errors.New, Wrapping & Custom Types

Creating errors with errors.New, wrapping them to add context, and defining your own custom error types.

03

All about the Go errors package

A closer look at the standard errors package and the tools it provides for working with errors.

04

Defer, Panic & Recover: Error Handling Patterns

How defer, panic and recover work together, and when they are the right tool compared with returning an error.