3 ms·
If I understand you correctly, then yes. fn canError(foo: bool) !void { if (foo) { return error.Foo; } else { retur
by squeek502 5y ago
If I understand you correctly, then yes.
fn canError(foo: bool) !void {
if (foo) {
return error.Foo;
} else {
return error.Bar;
}
}
test "canError" {
canError(true) catch |e| switch (e) {
error.Foo => @panic("foo!"),
};
}
Running `zig test` on that file would give:
./tmp/errors.zig:10:30: error: error.Bar not handled in switch
canError(true) catch |e| switch (e) {
^
- Zababa 5y agoYou did understand it correctly. That's a really nice feature.