users@jersey.java.net

Re: [Jersey] ExceptionMapper matching

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 27 Mar 2009 17:27:55 +0100

On Mar 27, 2009, at 5:18 PM, Andrew Ochsner wrote:

> Hi:
>
> I have a set of ExceptionMappers that look for particular runtime
> exceptions that i've created and maps them accordingly.
>
> I'd also like a generic one that looks for RuntimeExceptions and
> strips out the stack trace essentially.
>
> If I create an ExceptionMapper that converts RuntimException, what
> happens when I throw one of my specific ones for which there is a
> more specific mapper for?
>
> Sorry, hope that makes sense. Basically I want it to match as close
> as it can so that the specific mappers i've written get used before
> the generic RuntimeException mapper.
>
> Can this work?


Yes. See here:

   https://jsr311.dev.java.net/nonav/releases/1.0/spec/
spec3.html#x3-510004.4

Specifically:

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.

Paul.