jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Re: Exception hierarchy

From: Roberto Chinnici <roberto.chinnici_at_oracle.com>
Date: Fri, 04 Mar 2011 11:27:31 -0800

  Filed as JAX_RS_SPEC-48 [1].

[1] http://java.net/jira/browse/JAX_RS_SPEC-48

On 3/4/11 6:26 AM, Bill Burke wrote:
> Create an exception hierarchy for both the client and server side.
> For example:
>
> Internally, on the server side, if JAX-RS matches a @Path, but the
> Accept header doesn't match produced media types, the JAX-RS
> implementation should throw a
>
> UnsupportedMediaTypeException
>
> If users want custom output for that exception they can catch it via
> an ExceptionMapper. You'd have others for NotFoundException,
> NotAcceptableException, etc... each corresponding to a JAX-RS failure
> thrown by the runtime (not the users app).
>
> Another thing we do in Resteasy is to have wrapper exceptions for:
>
> ApplicationException - Wraps any thrown exception by the application
> ReaderException - Wraps any thrown exception by a MessageBodyReader
> WriterException - Wraps any thrown exception by a MessageBodyWriter
>
> That way, if a user wants to do its own special exception handling for
> all thrown exceptions from an application, they can write an
> ExceptionMapper for ApplicationException, same goes for other instances.
>
>
> On the client side, it depends what kind of higher-level framework is
> written on whether or not these exceptions are re-used on the client.
>