4 ms·
I think checked exceptions are a bad way of doing Result types (Result in Rust, Either in Haskell), and that those are generally better than unchecked exception
by hyperpape 8y ago
I think checked exceptions are a bad way of doing Result types (Result in Rust, Either in Haskell), and that those are generally better than unchecked exceptions. In my opinion, unchecked exceptions aren't that much different than checked exceptions. The difference is that you have to get them right at the level of documentation, not type signatures, and documentation usually doesn't have a compiler that will help you.
However, back in the Java 7 days, I think checked exceptions would've been made a lot better with a bit of syntactic sugar:
public void foo() rethrows* {
bar();
}
Where the meaning of the rethrows term is that the method throws whatever exceptions the methods it calls throws. The bottom level methods that throw exceptions would still have
This would make it easier to refactor code to change exception behavior. It would only be at the public API boundaries that you have to wrap exceptions to avoid changing the API or modify your method signatures.
Now that lambdas are here, checked exceptions are even more painful, so I don't think this solution would tip the balance. But for the language that we had, I think it would've helped a lot.
* rethrows might not be the best name. I'm more attached to the idea than the term.