I was writing some code, and I notice a pattern in the exception handling that got me thinking:
try{
// do stuff... throws JMS, Create and NamingException
} catch (NamingException e) {
log1(e);
rollback();
doSomething(e)
} catch (CreateException e) {
log1(e);
rollback();
doSomething(e)
}
Where JMSException would be handle some where up in the stack.
Would it be to just write:
try{
// do stuff... throws JMS, Create and NamingException
} catch Exception[NamingException, CreateException] e) {
log1(e);
rollback();
doSomething(e)
}
instead of putting it in tu a helper method:
try{
// do stuff... throws JMS, Create and NamingException
} catch (NamingException e) {
helper_handleError1(e)
} catch (CreateException e) {
helper_handleError1(e)
}
Notice that I want to propagate stacktrace of the original JMSException, and I don't "feel like" creating an new JMSException with a third catch clause :)
Any toughs? Is this an extreme situation that would only pollute the syntax of Java, or just a cool thing to add?