Lesson 30 of 38 · Interfaces & Errors
Quiz: Go Interfaces and Errors
You can now write flexible Go code with interfaces: types satisfy them implicitly, a slice of interface values lets one loop handle many types, and pointer receivers decide whether T or only *T implements an interface. Type assertions and type switches get concrete values back out, and the comma-ok form keeps them from panicking.
On the error side, you return error values instead of throwing exceptions, check if err != nil right away, declare sentinel errors, build custom error types, and wrap errors with %w so that errors.Is and errors.As can still find the cause. Answer these six questions before you face the chapter boss.
What this quiz covers
The questions check what you learned in the Interfaces & Errors chapter of Learn Go. Not sure about a topic? Review its lesson first:
- Go Interfaces: Implicit Implementation and Polymorphism
Learn Go interfaces: method sets, implicit implementation, polymorphism with slices of interfaces, pointer receivers, the empty interface any and nil.
- Go Type Assertions and Type Switches
Get concrete values back out of Go interfaces with type assertions, the comma-ok form and type switches, including case nil and multi-type cases.
- Go Error Handling: error Values and if err != nil
Learn Go error handling: the error interface, errors.New and fmt.Errorf, returning (value, error), if err != nil checks and sentinel errors with errors.Is.
- Go Custom Errors and Error Wrapping with %w
Create custom error types in Go, add context with fmt.Errorf and %w, and inspect error chains with errors.Is, errors.As, errors.Unwrap and errors.Join.
Keep learning
Need a quick reminder? The Go cheat sheet has every topic of Learn Go on one page.
Lesson last updated on .