0PricingLogin
Zig Academy · Lesson

Propagate Failures with try

Bubble errors up with one keyword.

Handling Gets Repetitive

Writing an if-else around every fallible call to forward its error gets noisy fast. Zig offers a shortcut: the try keyword.

try Unwraps or Returns

Put try before a fallible call. On success it hands you the value; on error it returns that error from your current function.

const n = try parse(input);

All lessons in this course

  1. Error Sets and the !T Union
  2. Returning Errors from Functions
  3. Propagate Failures with try
  4. Inferred Error Sets
← Back to Zig Academy