Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever
by h4x0rr on Thursday July 13, 2023 @06:32PM
(#36717043)
Checked exceptions just always felt annoying to work with. Imo Rust's Result type is more versatile
[ Parent
| on HN ]
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever
by wvenable on Thursday July 13, 2023 @07:23PM
(#36717436)
Checked exceptions are just another return type with a weird syntax. It's not that Rust's result type is more versatile, it's just less syntax to accomplish what works out to be the same thing.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever
by jcparkyn on Thursday July 13, 2023 @08:09PM
(#36717793)
The difference is more than just syntax, at least in the case of Java and Rust. The core problem with checked exceptions in Java (as demonstrated in most of the examples from TFA) is that they don't compose properly with generic functions like map. Checked exceptions exist in parallel to the type system, and other parts of the language don't have the capacity to deal with them.
On the other hand, a Result type makes errors part of the type system, and all other code can work with them "by default".
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever
by wvenable on Thursday July 13, 2023 @08:36PM
(#36718002)
I agree. Checked exceptions are just a worse version of Result types. I did not intend to make them sound better than they are.
Unchecked exceptions, however, are a different beast entirely. They're not just checked exceptions without the checking; they fundamentally change how you code and how you think about error handling.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever
by ben0x539 on Thursday July 13, 2023 @09:45PM
(#36718452)
Whoa, I've been having opinions about error handling and result types and checked exceptions for like years and I never considered that Java couldn't be "properly" polymorphic over checked exception types. Thanks for pointing that out.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever
by int_19h on Thursday July 13, 2023 @10:34PM
(#36718783)
That's a specific choice that Java designers made, though, not something inherent to checked exceptions in principle. During Project Lambda, one of the proposals - Neal Gafter's - actually had a full-fledged generic exception specification facility that allowed you to define HOFs along the lines of "I throw everything X does, and also Y". They killed it because it was "too complicated".
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever
by benjiweber on Friday July 14, 2023 @01:51AM
(#36719950)
You can use checked exceptions equivalently to Result types in streams
e.g. https://github.com/unruly/control/blob/master/src/test/java/...