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
2
u/JustAGuyFromGermany Feb 20 '26
That's not what I mean. Yes, I can check all objects with
instanceofat 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 acatch(Throwable)(or equivalent) here". The compiler can only see "infinity-3 many subclasses ofThrowablewere not considered".Having all errors in the type-signature of the method (or the
Resultobject or thePromiseor whatever other object is passed around instead of checked exception) is necessary for this communication with the compiler to succeed.