# Zig Level 5: Errors & Optionals

> Level 5: Errors & Optionals of the LoWisa Zig course: Error Unions, Optionals, Explicit Failure Handling. 3 lessons and 9 ideas, each explained in one line.

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

## 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

- **Before:** [Level 4: Structs, Enums & Unions](/courses/zig/level-4-structs-enums-and-unions/): Structs, Enums, Tagged Unions.
- **Next:** [Level 6: Comptime](/courses/zig/level-6-comptime/): Compile-Time Evaluation, Generic Programming, Compile-Time Code Generation.

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](/help/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.

---

Source: https://lowisa.dev/courses/zig/level-5-errors-and-optionals/ · Updated 2026-11-25
