3 ms·
I'd really like something to help with that issue. I really appreciate Zig's error handling right up until you need to pass along any info other than essentiall
by losvedir 4y ago
I'd really like something to help with that issue. I really appreciate Zig's error handling right up until you need to pass along any info other than essentially an error code. Then you have to throw away a lot of the syntax niceties and error tools that it gives you. I understand there's complications, though, with dynamic objects being returned up the stack, possibly requiring allocation, rather than a simple enum.
Rust gets this right for me, at a semantic level, where an Error is just an ADT with an arbitrary payload. However, while there's something to be said for consistency in a language and treating errors as any other values that you work with via `match` and any other ordinary language constructs, I really like that Zig has some syntactic sugar for working with it. Errors are so prevalent and necessary to deal with, they don't have to be exactly like ordinary values, and it's nice that, e.g., Zig has special handling for them in `if` statements, and ways of working with them in function signatures, and automatic error unions and such.
- skywal_l 4y agoTo be fair, Rust also comes with some specific `if` constructs to deal with error management and has the equivalent of zig's `try` with `?`. I also like that their Result object has many methods to express how you want to specifically handle error case (all the variations of unwrap, unwrap_or, or, etc...).