Zig course

Zig Level 5: Errors & Optionals

Errors & Optionals is level 5 of 11 of the LoWisa Zig course. It has 3 lessons and 9 ideas. Below is every lesson and what it teaches, in one line each.

Updated 2026-11-25

Error Unions

  • Error sets. An error set names failures: error{OutOfMemory, NotFound}: errors as types, not strings.
  • try. try propagates an error return early: the one-word question mark of Zig.
  • catch. catch handles or defaults: value = parse(s) catch 0: recovery inline and visible.

Optionals

  • Optionals. A ?T holds a value or null: absence in the type, unwrapped explicitly.
  • orelse. orelse supplies the fallback: name orelse "guest": absence answered inline.
  • if unwrapping. if (maybe) |value| unwraps into a capture: the branch owns a real value.

Explicit Failure Handling

  • errdefer. errdefer runs cleanup only on error paths: partially-built resources unwound exactly.
  • Error return traces. Debug builds carry error traces: the path an error travelled, printed on failure.
  • No exceptions ever. With no exceptions, every failure path is visible in the code that takes it.

Before and after this level

In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.

Frequently asked questions

What does Zig Level 5: Errors & Optionals cover?

Error Unions, Optionals, Explicit Failure Handling: 3 lessons and 9 ideas.

What should I know before this level?

The level before it, Level 4: Structs, Enums & Unions, which covers Structs, Enums, Tagged Unions.

Learn Zig on your phone

The first level is free. LoWisa is on Google Play and the App Store.