Let's say I have 3 exception classes that I want to "catch":
I want the WebApplicationException to be still mapped automagically by Jersey, MyException to be mapped by MyMapper and to be sure that any other exceptions are also mapped by MyFallbackMapper.
So because any exceptions (that I want to control) finally extend Exception, is there any guarantee that MyMapper (and not MyFallbackMapper) will be used for MyException?
JAX-RS 1.1 spec, chapter 4.4:
When a resource class or provider method throws an exception, the JAX-RS runtime will attempt to map the exception to a suitable HTTP response - see section 3.3.4. An application can supply exception mapping providers to customize this mapping.
Exception mapping providers map a checked or runtime exception to an instance of Response. An excep- tion mapping provider implements the ExceptionMapper interface and is annotated with @Provider. When a resource method throws an exception for which there is an exception mapping provider, the match- ing provider is used to obtain a Response instance. The resulting Response is processed as if the method throwing the exception had instead returned the Response, see section 3.3.3.
When choosing an exception mapping provider to map an exception, an implementation MUST use the provider whose generic type is the nearest superclass of the exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With