mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
This allows for errors to be "re-thrown" by yielding any error as the
result of a catch block. For example:
```zig
fn errorable() !void {
return error.FallingOutOfPlane;
}
fn foo(have_parachute: bool) !void {
return errorable() catch |err| b: {
if (have_parachute) {
// error trace will include the call to errorable()
break :b error.NoParachute;
} else {
return;
}
};
}
pub fn main() !void {
// Anything that returns a non-error does not pollute the error trace.
try foo(true);
// This error trace will still include errorable(), whose error was "re-thrown" by foo()
try foo(false);
}
```
This is piece (2/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
|
||
|---|---|---|
| .. | ||
| behavior | ||
| c_abi | ||
| cases | ||
| link | ||
| src | ||
| stage2 | ||
| standalone | ||
| assemble_and_link.zig | ||
| behavior.zig | ||
| cases.zig | ||
| cli.zig | ||
| compare_output.zig | ||
| compile_errors.zig | ||
| gen_h.zig | ||
| link.zig | ||
| run_translated_c.zig | ||
| stack_traces.zig | ||
| standalone.zig | ||
| tests.zig | ||
| translate_c.zig | ||