▲ | zaphar 4 days ago | |||||||||||||
To be fair, Rust could have done CheckedExceptions like Java has but no one uses. The problematic version is the RuntimeException. I think the real problem was that when Rust conceived of Result they didn't constrain the problem to just error handling and made it a little bit too much "anything goes". Which means that trying to shoehorn backtraces in after the fact with `?` and `try_into` is now hard. There could have been a world where `Result::Err` was actually a wrapper type that specified an optional source error for backtracing and the generic type was embedded in that instead. It would have been less flexible but it would have made proper backtraces more tractable. | ||||||||||||||
▲ | ninkendo 4 days ago | parent [-] | |||||||||||||
Is there a language that has proper exclusively checked exceptions? That is, not just syntax sugar around checking an error value (à la Swift), but actual “the processor signals an exception” semantics, but all exceptions are still enforced to be handled-or-passed by the compiler? Honest question, because I can’t think of any. I can see it being advantageous to have checked-only exceptions but there has to be a good reason why it’s so rare-to-never that we see it. I’m not sure how else you’d get the holy grail, which I’d define as: 1. The compiler enforces that you either handle an exception or pass it to the caller 2. Accurate and fine-grained stack traces on an error (built-in, not opt-in from some error library du jour) 3. (ideally) no runtime cost for non-exception paths (no branches checking for errors, exceptions are real hardware traps) C++ has 2 and 3, Java has only 2 (because RuntimeException exists), Rust has only 1. I’d love a language with 1 and 2, but all 3 would be great. | ||||||||||||||
|