If you are using Spring, then why not go for a specific exception handler for specific type.
You can have one GlobalException handler and tag it to your controller
@ControllerAdvice(assignableTypes = {YourController.class})
public class MyGlobalExceptionHandler {
Then you can have specific handler methods to handle specific exception.
for e.g. below is handling specific ServerWebInputException
@ExceptionHandler(ServerWebInputException.class)
public ResponseEntity<YourResponseObject> handleValidationError(final ServerWebInputException badRequest) {
}
and you can have a generic Throwable handler
@ExceptionHandler(Throwable.class)
public ResponseEntity<YourResponseObject> handleThrowable(final Throwable throwable) {
This would be a clean solution.
catch
a throwable and then interrogate its class to see if it's a NoSessionException or whatever. – Lactoprotein