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

[jsr339-experts] Exception hierarchy

From: Bill Burke <bburke_at_redhat.com>
Date: Fri, 04 Mar 2011 09:26:17 -0500

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.

-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com