←back to thread

517 points bkolobara | 1 comments | | HN request time: 0s | source
Show context
aeve890 ◴[] No.45042188[source]
>The code will compile just fine. The Zig compiler will generate a new number for each unique 'error.*'

This is wild. I assume there's at least the tooling to catch this kind of errors right?

replies(3): >>45042403 #>>45042586 #>>45050319 #
TUSF ◴[] No.45042403[source]
There's no special tooling to catch this, because nobody catches an error with if-else—it's simply not idiomatic. Everyone uses switch statements in the catch block, and I've never seen anybody using anything other than switch, when catching an error.
replies(4): >>45042474 #>>45042605 #>>45043295 #>>45043644 #
1. veber-alex ◴[] No.45042474[source]
But why?

If I just need to check for 1 specific error and do something why do I need a switch?

In Rust you have both "match" (like switch) and "if let" which just pattern matches one variant but both are properly checked by the compiler to have only valid values.