문제

I am currently refactoring an existing codebase (EJBs) to rip out all blocks where a Throwable is caught 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, jboss, etc.). I searched via Google and had a look at the weblogic docs but wasn't able to find anything, just generic java doc.

도움이 되었습니까?

해결책

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.

다른 팁

  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"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top