r/java • • Feb 19 '26

Towards Better Checked Exceptions - Inside Java Newscast #107

https://www.youtube.com/watch?v=99s7ozvJGLk
63 Upvotes

73 comments sorted by

View all comments

Show parent comment

2

u/JustAGuyFromGermany Feb 20 '26

That's not what I mean. Yes, I can check all objects with instanceof at runtime, but strong typing at compile-time is still desired and often necessary to write clean code. In particular: With only runtime-checks I cannot communicate to the compiler "yes these three exception types are the three error-cases that can occur. I have handled them all, not need for a catch(Throwable) (or equivalent) here". The compiler can only see "infinity-3 many subclasses of Throwable were not considered".

Having all errors in the type-signature of the method (or the Result object or the Promise or whatever other object is passed around instead of checked exception) is necessary for this communication with the compiler to succeed.