[jboss-dev] throws Throwable
Brian Stansberry
brian.stansberry at redhat.com
Thu May 7 09:43:23 EDT 2009
Carlo de Wolf wrote:
> Jason T. Greene wrote:
>> Carlo de Wolf wrote:
>>> Andrew Lee Rubinger wrote:
>>>> Jason T. Greene wrote:
>>>>> Max Rydahl Andersen wrote:
>>>>>>
>>>>>>
>>>>>> Tim Fox wrote:
>>>>>>> David M. Lloyd wrote:
>>>>>>>> On 05/05/2009 03:02 AM, Carlo de Wolf wrote:
>>>>>>>>> What's the use case for having a public method:
>>>>>>>>> doSomething(Object someArgs...) throws Throwable ?
>>>>>>>>
>>>>>>>> No valid use cases exist afaik. Any method that throws
>>>>>>>> Throwable should die, if it's within our power to kill it.
>>>>>>> Declaring a method as "throws Throwable" forces the caller to
>>>>>>> handle the exception even if the exception/error thrown is
>>>>>>> unchecked.
>>>>>> Then do throws RuntimeException
>>>>>>
>>>>>> Error's are *nonrecoverable* since they are OutOfMemory or hard VM
>>>>>> errors.No client can ever recover sanely.
>>>>>
>>>>> One valid case for throwing Throwable is a generic invocation
>>>>> mechanism
>>>>> (interceptors, proxies, etc).
>>>>
>>>> Just because it's generic doesn't mean the caller can do anything
>>>> about it. In that case why not just "throws Exception"?
>>> As per javax.interceptor.InvocationContext.proceed().
>>> But InvocationHandler.invoke throws a Throwable, which I think is wrong.
>>
>> IMO this is correct because the Java language allows user code to
>> throw errors, and an interceptor should be able to throw any exception
>> declared by the method it is emulating. The only alternative is to
>> wrap it with a special exception that gets unwrapped, but this is just
>> pointless copying.
>>
> I disagree: it should be: invoke(..) throws Exception.
> Both the user code and the invoke can throw unchecked exceptions
> nonetheless. It's the handling of a checked exception that doesn't fit
> the given method signature that gets special treatment.
> Ergo throws Throwable in this case is still wrong.
>
The user code can also throw new Throwable(...). Not an Error, not an
Exception, just a Throwable. Any code that did that should be taken out
and shot, but it is allowed. And per section 11.2 of the JLS, that's a
checked exception:
"The unchecked exceptions classes are the class RuntimeException and its
subclasses, and the class Error and its subclasses. All other exception
classes are checked exception classes. "
> Carlo
> _______________________________________________
> jboss-development mailing list
> jboss-development at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jboss-development
--
Brian Stansberry
Lead, AS Clustering
JBoss, a division of Red Hat
brian.stansberry at redhat.com
More information about the jboss-development
mailing list