3 ms·
Zig's `errdefer` is really cool. While I like the semantic simplicity of, e.g., rust's Result for errors, and treating an error like any other value, having a l
by losvedir 5y ago
Zig's `errdefer` is really cool. While I like the semantic simplicity of, e.g., rust's Result for errors, and treating an error like any other value, having a little language special handling for errors is very nice. Zig's equivalent of "Result" with special notation for errors, and `errdefer` and all that simplifies a very common, important programming task. I think language design is all about finding those things that you do all the time and make them a little smoother to handle.
That said, one issue with the Zig approach is all the application's errors boil down to an integer set (with easy mapping to names). If you want to pass along data with the error, you sort of have to fall back to a "result" value type, and lose all the great error handling machinery, or do other workarounds. I think Zig's special handling of errors, but for arbitrary errors with data (like Result.Err in rust), would be the best of both worlds. But there's probably significant implementation hurdles with that that I don't know about.
- dralley 5y agoThere's a discussion about this here: https://github.com/ziglang/zig/issues/2647 https://github.com/ziglang/zig/issues/2647