users@jsr311.java.net

Re: Telling ExceptionMapper to exclude exceptions

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Fri, 10 Oct 2008 11:40:02 -0400

Hi Marc,

    I'd like to process all uncaught RuntimeExceptions thrown by
resource methods. I'm simply trying to ensure that resource methods
returns a valid response even if the code forgets to catch an exception.
Now, I could add try{}catch blocks on a per-method basis one by one but
it seems like there should be a better mechanism for doing this that is
easier to maintain. And besides, if I forgot to catch some exception in
the first place it seems equally likely that I forgot to surround the
code with a try{}catch block.

Gili

> On Oct 3, 2008, at 8:35 AM, cowwoc wrote:
>>
>> We need a portable mechanism to tell ExceptionMapper to catch all
>> application-generated RuntimeExceptions but pass-through all
>> exceptions generated by the underlying JAX-RS implementation (meant
>> to be handled by the container, not our code). I suspect this is a
>> very common use-case but there doesn't seem to be a way to do it.
>>
> Can you say a bit more about what you are trying to achieve. Only
> certain exceptions are required to be processed by exception mappers:
>
> - those thrown by a resource method
> - those thrown by a provider method
> - those thrown by the ctor or valueOf method of a resource field,
> property or method parameter
>
> It sounds like you want to be able to distinguish between say an
> IllegalArgumentException thrown by UriBuilder vs one thrown by some
> other API that a resource method uses but I'm struggling to see a use
> case for that.
>
> Thanks,
> Marc.
>
> ---
> Marc Hadley <marc.hadley at sun.com>
> CTO Office, Sun Microsystems.
>
>