views:

145

answers:

2

hi all,

i am currently refactoring an existing codebase (EJBs...) to rip out all blocks where a Throwable is catched inside of the EJB.

try {
    ... do some business logic
} catch(Throwable t){
    ... log and swallow ... :-(
}

i want/need to convince the people around me with proper documentation that "catching throwable" is a no-go for an EJB (we have lots of discussions around this :-(( ). weblogic will handle all the "Error" conditions and maybe invalidate EJBs and put fresh(working) EJBs into the pool. catching Throwable would undermine all these security nets provided by weblogic. and catching throwable is bad practice anyway (but people here are reluctant and use the "throwable" hammer everywhere).

is anyone able to point me to some online docs where this behaviour is explained (for weblogic or jboss or...). i searched via google and had a look at the weblogic docs but wasn't able to find anything, just generic java doc.

any help highly appreciated

cheers marcel

+1  A: 
  1. Buy a copy of Effective Java, Second Edition by Joshua Bloch for every member of your team.

  2. Have everyone read Chapter 9, "Exceptions", which covers:

    • "Use exceptions only for exceptional conditions"
    • "Use checked exceptions for recoverable conditions and runtime exceptions for programming errors"
    • "Avoid unnecessary use of checked exceptions"
    • "Favor the use of standard exceptions"
    • "Throw exceptions appropriate to the abstraction"
    • "Document all exceptions thrown by each method"
    • "Include failure-capture information in detail messages"
    • "Strive for failure atomicity"
    • "Don't ignore exceptions"
matt b
While this is sound advice, I think his question was about proving that Weblogic will invalidate session EJBs when their methods throw uncaught exceptions.
Sean Owen
matt b, thanks for your quick reply. i have the copy of the book ;-).i need some doc in the context of app servers (like weblogic). especially that EJB code should not catch "Errors" like OutOfMemoryError etc.. And how appservers treat these error conditions. i want to rip all the bad throwable error handling out. but people can't be easily convinced here. hope you know what i mean. cheers
Marcel
well, it's arguable and accepted that no code beyond the top-layer should ever be catching Errors - certainly doing so in EJB layers (or servlet layers, or DAO layers, etc) is a bad practice.
matt b
cheers guys, i guess the best is really to throw them the pudding into the face....thanks for your helpbut anyway some weblogic doc would still be appreciated ;-)
Marcel
+2  A: 

They say, the proof is in the pudding.

Write a small example that does nothing but throw different kinds of exceptions ( Runtime, Errors ) and demonstrate that your container gracefully handles them.

This will stop the critics dead in their tracks.

Alexander Pogrebnyak
Indeed, let them *experience* it themselves. Own experience is the best experience.
BalusC