Curriculum Errors Error union returns (!T)
Error union returns (!T)
A function that can fail declares a return type with a leading bang: !T means "either a T or an error." The error set is usually INFERRED from the function body — every return error.X line is added to the implicit set. !void is the common shape for functions that succeed silently or fail (validators, writers). The caller consumes via try, catch <default>, or catch |err| handler. The bang plus a body that mentions error.X is the whole error story.
9 ready
01
pick one TypeScript writes function divide(a: number, b: number): number
02
pick oneWhen a function CAN fail but has no meaningful success value
03
pick oneWhen you DO want to pin down which errors a function can
04
fill blanksFill the missing single character that marks a function's
05
fill blanksFill the missing payload type for a function that fails-or-
06
type one lineType the missing Zig signature — declare `divide(a: i32,
07
type one line Type the missing Zig signature — validate takes a slice
08
write a programWrite a complete Zig program with an explicit-set error
09
write a programWrite a complete Zig program that mixes inferred and