users@jsr311.java.net

Re: Telling ExceptionMapper to exclude exceptions

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Fri, 10 Oct 2008 13:46:56 -0400

On Oct 10, 2008, at 11:40 AM, cowwoc wrote:
>
> 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.

That's what ExceptionMapper is designed to do. I don't understand
which exceptions you want to exclude however ? An example might be
useful.

Thanks,
Marc.

> 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.
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: users-help_at_jsr311.dev.java.net
>

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.