2 ms·
No one here mentioned Zig approach there, so I'll share: https://ziglang.org/documentation/master/#try https://ziglang.org/documentation/master/#try Zig has tr
by ivanjermakov 1y ago
No one here mentioned Zig approach there, so I'll share: https://ziglang.org/documentation/master/#try https://ziglang.org/documentation/master/#try
Zig has try syntax that expands to `expr catch |e| return e`, neatly solving a common use case of returning an error to the caller.
- joaohaas 1y agoZig 'error types' are a sum type, while Go ones are just values. And even then this is just the same as the '?' operator Rust uses, which is mentioned in the post.
- tubthumper8 1y agoThe "Error Return Trace" described in the next section down also seems like an interesting alternative to a stack trace, possibly solving the same problem with less noise. How well does it work in practice?
- kristoff_it 1y agoIt works really, really well, in part because it's also capable of tracking where an error is turned into another. And the error return trace ends where the stack trace begins (when an error is turned into a panic) so you don't even have to know what an error trace is, because it just makes sense intuitively.