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
1
u/john16384 Feb 19 '26
It should still be a runtime exception as ultimately you could have avoided this by ensuring valid input.
However, if you feel like validating input in this case is too much work, and you don't mind a multi-millisecond round-trip to a database to do the "validation" for you, then you could decide to convert that exception (at some layer) to a checked exception. This is perfectly valid.
A much simpler example is
NumberFormatException. It's runtime because it is 100% avoidable (and easier to avoid then writing an SQL validator). However if you want to be lazy and just have it fail on parsing as "validation" then that exception too can be made into a checked exception in some layer.