According to [1],
"When deciding on checked exceptions vs. unchecked exceptions, ask yourself, What action can the client code take when the exception occurs?. If the Client code cannot do anything, Make it an unchecked exception. And if the Client code will take some useful recovery action based on information in the exception, make it a checked exception."
I get the overall idea. However, my confusion is, what it meant by the "Client code". Let's say I'm writing a REST API, which has a Service Layer that calls the Actual Backend Layer (where I do the validation as well).
API User --calls--> { |Service Layer| --internally calls--> |Backend Layer| }
- So the API User is also considered as a "Client code"?
- For request validations, should I throw Checked or Unchecked Exceptions?
- Is the best practice to avoid using checked exceptions?
- Is is ok to throw unchecked exceptions in validations, and let it bubble up, and catch and wrap it with in a custom exception at the Service Layer? (and use JAX-RS ExceptionMapper [3] to show that to the API user)
References:
[1] http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html
[2] http://archive.oreilly.com/pub/post/avoiding_checked_exceptions.html
[3] https://docs.oracle.com/javaee/6/api/javax/ws/rs/ext/ExceptionMapper.html