Re: [Jersey] exception handling best practices

From: Chris Carrier <>
Date: Wed, 24 Feb 2010 12:17:48 -0800

So if I want to use exceptionMappers to deal with mapping to Responses
I'd also want to do my logging there probably. In that case I'd want
to log the input field (query parameters). Is there any access to the
request context in the ExceptionMappers?


On Tue, Feb 23, 2010 at 2:41 PM, Tatu Saloranta <> wrote:
> On Mon, Feb 22, 2010 at 12:02 PM, Craig McClanahan <> wrote:
> ...
>> My favorite approach is to create exception classes (extending
>> RuntimeException or WebApplicationException) that correspond to
>> various error conditions, then use ExceptionMapper to map them to an
>> appropriate status code with an appropriately formatted message (with
>> an appropriate media type).  With these, I can tell a developer
>> writing a GET method in a resource class, that when the user tries to
>> access a resource that doesn't exist, just "throw
>> NotFoundException(...)" and let Jersey take care of remembering that
>> this should be a 404 with the correct media type and message format.
> For what it's worth, that is similar to what I like to do. There's
> limited number of exception types that are commonly needed, so
> overhead tends to grow logarithmically; at first it may seem like lots
> of extra work, but not so much for the long run. And it does decouple
> things reasonably well.
> But I agree in that there's more than one way to skin the cat,
> -+ Tatu +-
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail: