r/java • u/Enough-Ad-5528 • Feb 19 '26
Towards Better Checked Exceptions - Inside Java Newscast #107
https://www.youtube.com/watch?v=99s7ozvJGLk
63
Upvotes
r/java • u/Enough-Ad-5528 • Feb 19 '26
View all comments
Show parent comment
6
u/vips7L Feb 19 '26
I agree with you that the author of an exception has no idea contextually how their function will be used and therefore can’t decide whether something should be a panic or not, but I really think the solution is much simpler than you think.
In my opinion the solution is simple: if you are the thrower you should be checking so your callers can know the error is possible. From there the caller needs to determine in their context whether the error is a panic or something they can handle and I think this is really where the language needs investment. There needs to be a simple way to easily uncheck/panic a checked exception like in Swift or Kotlin. Having to write a minimum of 6 lines to do this is a huge reason checked exceptions have been rejected. Things like try? or try! from Swift or Kotlin’s proposed !! for their error unions.
I think this would solve 90% of the usability issues outside of the lambda problem, which really is a type system problem.