Yeah but Go has the best error handling paradigm of any programming language ever created:
ret, err := do_thing()
if err != nil {
return nil, err
}
Don’t you just love doing that every 5 lines of code?
I do think Zig is better for this kind of thing.
const ret = try do_thing();
if( ret ) | result | {
do_something_with_result(result);
}
The try keyword returns any error up; the if-unwrap works with what came out of a successful call. Normally you wouldn’t have both, of course.
do_thing would be defined as a union of an error (a distinct kind of type, so it can be reasoned about with try, catch and unwrapping) and the wrapped return value.
With some sprinkle of libraries such as anyhow
and thiserror
the Rust errors become actually pleasant to use. The vanilla way is indeed painful when you start handling more than one type of error at a time.