logoalt Hacker News

ivanjermakovlast Tuesday at 10:36 PM2 repliesview on HN

No one here mentioned Zig approach there, so I'll share: 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.


Replies

tubthumper8last Wednesday at 4:25 AM

The "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?

show 1 reply
joaohaaslast Tuesday at 10:44 PM

Zig '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.