views:

40

answers:

1

So in my JAXRS application, I have 2 ExceptionMapper registered as @Provider

public class MyExceptionMapper implements ExceptionMapper<Exception> {...}

public class MyCustomRuntimeExceptionMapper implements ExceptionMapper<MyCustomRuntimeException> {...}

When my application throws a new "MyCustomRuntimeException", the exception is caught inside the MyExceptionMapper, even though (JAX-RS spec says) it should be caught inside MyCustomRuntimeExceptionMapper.

Here's what JAXRS says -

JAX-RS supports exception inheritance as well. When an exception is thrown, JAX-RS will first try and find an ExceptionMapper for that exception’s type. If it cannot find one, it will look for a mapper that can handle the exception’s superclass. It will continue this process until there are no more superclasses to match against.

Anyone have a clue, whats going on here? Thanks.

A: 

I had a problem with this too. It appears as if it finds the superclass of the exception before looking for the subclass. This keeps me from having an ExceptionMapper for Exception. There's an application-specific exception I have to deal with that has subclasses; I can't have separate exception mappers for them. I have one exception mapper for the superclass and then a bunch of "if (e instanceof SubClassA)" statements.

Mark Lutton
yea i ended up doing the same :) thx much