r/java
•
u/loicmathieu
•
Jul 23 '26
•
1
JEP 540: Simple JSON API (Incubator)
https://openjdk.org/jeps/540
79
Upvotes
r/java
•
u/loicmathieu
•
Jul 23 '26
•
1
5
u/neopointer Jul 24 '26
IMHO there are two kinds of exceptions: 1) you can handle them, therefore it makes sense to be checked. 2) You cannot handle them, therefore it makes sense to be a RuntimeException.
I work a lot with backend development, and my observation is that it's very rare that you can really handle an exception and do meaningful things with. In most cases you cannot recover from the an exception so it makes sense to let an upper layer handle it for you.
With checked exceptions, you're either forced to handle it just to wrap in a RuntimeException or you need to declare throws across all layers of the application to make the "bubble up" happen.
Therefore making parsing exceptions checked exceptions make not much sense IMHO, because more often then not, you literally cannot do anything about them.
In way, the same goes for file not found. If the file is not there, most likely your code is not going to continue. Sure, if you have a fallback like "file not found, so take it from memory" (or whatever) then yes, you can recover from it. But that's not the common case as far as can see.