Curriculum Errors try and catch exercise 1 · mcq
try and catch
TypeScript reaches for try { ... } catch (e) { throw e; } to
propagate an error to the caller. Zig has a single keyword
that does this in one line — call the function with try
and the error propagates to the enclosing function's return.
Pick the right shape.
About this theme
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.