I wrote code, and I notice a pattern in exception handling that made me think:
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 a JMSException will handle some of them on the stack.
It would be simple to write:
try{ // do stuff... throws JMS, Create and NamingException } catch Exception[NamingException, CreateException] e) { log1(e); rollback(); doSomething(e) }
instead of putting it in a helper method:
try{ // do stuff... throws JMS, Create and NamingException } catch (NamingException e) { helper_handleError1(e) } catch (CreateException e) { helper_handleError1(e) }
Note that I want to distribute the stacktrace of the original JMSException, and I don't feel like creating a new JMSException with the third catch clause :)
Any gestures? Is this an extreme situation that will only contaminate Java syntax or just a cool thing to add?
source share