[jboss-dev] throws Throwable

Tim Fox tim.fox at redhat.com
Wed May 6 12:43:15 EDT 2009


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.

FWIW It's debatable if it's really of much value but cases like the 
above are where I have seen it used.
>
> - 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