users@jersey.java.net

Re: [Jersey] exception handling best practices

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Mon, 22 Feb 2010 12:12:05 -0500

On Feb 22, 2010, at 11:54 AM, Florian Hehlen wrote:
>
> I am wondering if there is a recommended way to map exceptions with jax-rs/jersey. I have been playing around with all the different exceptions that extend WebApplicationException, I have in some cases just pushed runtime exceptions back to the framework, and I have also considered using the ExceptionMapper interface. I realize that I could extend WebApplicationException to create my own exceptions aswell, but is that wise?
>
> - I would like to have the most consistent relationship between application exceptions/errors and HTTP codes.
> - I would also like to guarantee that a human readable message and a stacktrace travel with all my errors back to the client. Yet it seems that this happens with certain types of exceptions but not with others.
> -I would also like to spend the least amount of time/energy on maintaining all these different possible states.
>
> Is there one approach that's better than others? I can't at first glance see one. Am I missing something? Does anyone have any recommendations experiences?
>
Personally I prefer use of ExceptionMapper(s) as they provide a nice centralized model for dealing with application exceptions. I think they should fulfill all your requirements, if not please provide more detailed issues that you've run into while experimenting with this approach.

Marc.