r/java
•
u/loicmathieu
•
Jul 23 '26
•
1
JEP 540: Simple JSON API (Incubator)
https://openjdk.org/jeps/540
79
Upvotes
View all comments
Show parent comment
4
u/vetronauta Jul 26 '26
Any exception is avoidable for anything not-network related: just check that any precondition is satisfied!
To cite Joshua Block: use runtime exceptions to indicate programming errors.
Receiving an invalid json in an http request and passing it to the parser is not a programming error, it is the whole point of the parser! Such exception must be handled properly, returning 400. Other times the same action (passing an invalid string to a parser) is unrecoverable (example: config files), but it is the caller that should decide that, and wrap it in a runtime exception.