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 Sep 14, 2022
1 parent 747ed9f commit a5957dc
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 88 deletions.
Loading

0 comments on commit a5957dc

Please sign in to comment.