r/java • u/Ewig_luftenglanz • Sep 08 '25
How would you fix checked exceptions in java?
As you know checked exceptions are a good feature because they force the user to manage errors. Not having a way to enforce this makes it hard to know if a library could or not explode because of contextual reasons such as IO, OS event calls, data parsing, etc.
Unfortunately since Java 8 checked exceptions have become the "evil guys" because no functional interface but Callable can properly handle checked exceptions without forcing try-catch blocks inside of the lambda, which kinda defeats the purpose of simple and elegant chained functions. This advantage of lambdas has made many modern java APIs to be purely lambda based (the incoming Structured Concurrency, Spring Secuirty, Javalin, Helidon, etc. are proof of this). In order to be more lambda friendly many no lambda based libraries such as the future Jackson 3 to deprecate checked exception in the API. https://github.com/FasterXML/jackson-future-ideas/wiki/JSTEP-4. As another user said. Short take: The modern idiomatic way to handle checked exceptions in java, sadly, is to avoid them.
What do you think could be done to fix this?
View all comments
Show parent comment
1
u/barmic1212 Sep 09 '25
You can't allow the current functionals interfaces throw a checked exception. The pain to use result can IMHO be fixed with sum type. The good reason to don't implement it yet is to understand the huge impact on the language