You can catch unhandled exceptions
thrown in Spring REST handlers in a
HandlerExceptionResolver.
Slide 4
Slide 4 text
This documentation for this interface is
at:
http://docs.spring.io/spring/docs/3.0.
x/api/org/springframework/web/servlet/Hand
lerExceptionResolver.html
Slide 5
Slide 5 text
When an exception is caught, you could
add code to check for another class that
could this exception by returning a more
specific message, defaulting to a standard
message if one could not be found.
Slide 6
Slide 6 text
For example, the
HttpRequestMethodNotSupportedExceptionHand
ler could handle requests to an endpoint
with a non-supported HTTP verb.
Slide 7
Slide 7 text
The GlobalExceptionHandler would simply
proxy onwards to this class.
Slide 8
Slide 8 text
These classes would effectively catch the
exception and return a pretty message to
the client. They have full access to the
exception.
Slide 9
Slide 9 text
A log should be made when an exception
wasn’t handled by a specific class:
I wasn't able to find a custom
ExceptionHandler for the exception '{}'
are you sure you want to handle this with
the GlobalExceptionHandler? exception: {}
Slide 10
Slide 10 text
They are Exceptional
Slide 11
Slide 11 text
Do not use Exceptions for flow control.
They are for exceptional circumstances,
it’s all in the name.