Hacker News new | ask | show | jobs
by layer8 1039 days ago
Checked exceptions are one of the main reasons I’m sticking with Java, even though Java lacks the ability to abstract over sets of checked exceptions, which does cause some inconvenience. It’s unfortunate that no other mainstream languages have been taking that approach.
2 comments

In languages with a Result type (or Either monad), you basically do have checked exceptions, even though the language has no exceptions.
With result types, you typically don’t get automatic exception propagation. I agree that overall it’s a spectrum of syntactic convenience, checked exceptions effectively form a sum type together with the regular return type.
Java also has that option. There is an excellent library called vavr. It adds the Try and Either monad to Java.
That sounds awesome! Do you have that flag set on a big codebase? Was it a big hassle to turn it on (like you had to remediate a bunch of code that didn't handle exceptions before you could check it in). Have you seen any big changes since enabling it?
Checked exceptions in Java are the default state and much of the standard library uses them.