Skip to content

Commit

Permalink
stage2: Do not pop error trace if result is an error
Browse files Browse the repository at this point in the history
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 ziglang#1923 (comment)
  • Loading branch information
topolarity committed Oct 15, 2022
1 parent 52dd482 commit e3d8bd6
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 89 deletions.
Loading

0 comments on commit e3d8bd6

Please sign in to comment.