Curriculum Errors try and catch
try and catch
There are three ways to consume an error union. try expr is the propagator: on error, return the error to the caller; on success, unwrap the value. expr catch <default> substitutes a fallback value (analogous to optionals orelse). expr catch |err| { ... } captures the error and runs a handler block — pair with a switch on err to handle each case. Once these three are reflex, error handling reads cleanly without exception-handler ceremony.
9 ready
01
pick one TypeScript reaches for try { ... } catch (e) { throw e; } to
02
pick oneWhen you'd rather substitute a DEFAULT VALUE for an error
03
pick oneWhen you need to RUN code on the error path (log it, print
04
fill blanksFill the missing keyword that propagates an error from a
05
fill blanksFill the missing keyword that consumes an error union and
06
type one line Type the missing Zig line — call maybe(7) with try so its
07
type one line Type the missing Zig line — bind n to the result of
08
write a programWrite a complete Zig program that:
09
write a programWrite a complete Zig program that uses payload-capture