0Pricing
Zig Academy · Lesson

Wrapping and Re-throwing Errors

Add context as errors travel up.

Errors Travel Upward

When a function cannot handle a failure itself, it passes the error to its caller. Along the way you can adjust or re-throw it.

Re-throw with try

The simplest re-throw is try. It forwards the original error unchanged to your caller, so the same value keeps bubbling up.

const data = try readFile(path);

All lessons in this course

  1. Recover with catch
  2. Switch on Specific Errors
  3. errdefer for Failure Cleanup
  4. Wrapping and Re-throwing Errors
← Back to Zig Academy