I think it's nice to have two mechanisms for errors like in ML: sum types for errors that the calling function can realistically recover from, and exceptions for the rest.
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) {
^You get compile errors if you try to handle an impossible error, or don't include an `else` prong (in which case the compiler tells you the full set of unhandled errors).