[jboss-dev] throws Throwable

Tim Fox tim.fox at redhat.com
Thu May 7 11:07:48 EDT 2009


David M. Lloyd wrote:
> On 05/06/2009 11:43 AM, 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.
>>
>> E.g.
>>
>> void storeMessage(Message message) throws Throwable
>> {
>> }
>>
>> If that method fails in any way, even if it throw a RuntimeException 
>> or Error then we need to handle it, since it would be a major problem 
>> if the message didn't get saved.
>>
>> The method could be declared to not throw Throwable and the caller 
>> would just have to remember to catch (Throwable) but declaring the 
>> method as throws Throwable prevents the possibility of the caller 
>> from forgetting to do so.
>
> That's a terrible idea.  Please - never do this. :-)
Like I said in the previous mail, I'm not recommending people do this, 
I'm reporting where I've seen it used in other code.

My personal view is all checked exceptions and throws clauses are evil.
>
> The furthest one should go towards "reminding" the user to handle a 
> runtime exception is to add that exception to the "throws" clause of 
> the method, and document it.
>
> - DML
>
> _______________________________________________
> jboss-development mailing list
> jboss-development at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jboss-development


-- 
Tim Fox
Messaging Lead
JBoss - a division of Red Hat

http://jbossfox.blogspot.com/

irc.freenode.net#jbossmessaging

fox at redhat.com




More information about the jboss-development mailing list