# stage2: Do not pop error trace if result is an error · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/0c3a50fe1c1370c975d7de1f2f00458b4a3ec299)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 0c3a50fe1c1370c975d7de1f2f00458b4a3ec299

Requested commit: 0c3a50fe1c1370c975d7de1f2f00458b4a3ec299

Commit: 0c3a50fe1c1370c975d7de1f2f00458b4a3ec299

Tree: 0e282d7a4702780f75ccebba7b9e7937d4e59985

Author: Cody Tapscott

Committer: Cody Tapscott

## Message

````
stage2: Do not pop error trace if result is an error

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

````

## Parents

- [eda3eb1561ec9a68e692821d5de71d03e6f50d42](https://git.cafe/gitcafe/zig/commit/eda3eb1561ec9a68e692821d5de71d03e6f50d42?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/0c3a50fe1c1370c975d7de1f2f00458b4a3ec299?format=markdown)
