struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hubert Rabago <jakartau...@yahoo.com>
Subject Exception Handling in Action objects
Date Mon, 03 Nov 2003 17:40:48 GMT
What's your approach to handling exceptions in your Action objects?
Do you have a "catch (Exception e)" in your actions with special clauses for 
specific cases?
I'm thinking of going this way:

public ActionForward execute(...) 
        throws Exception {

    // get values from parameters 
    // return getInputForward() if needed
    // call ejb for business processing 
    // return appropriate ActionForward

}

and then set up global ExceptionHandlers for exceptions I can't recover from 
anyway, like RemoteException etc.  If there are specific exceptions I
want to handle in a particular Action, I will:

public ActionForward execute(...) 
        throws Exception {

    // get values from parameters 
    // return getInputForward() if needed
    try {
       // call ejb for business processing 
    } catch (SpecificException e) {
       // handle "e" gracefully
    } 
    // return appropriate ActionForward
    // other exceptions handled through ExceptionHandlers

}

Do you have a "catch (Exception e)" so it's handled locally?
On one hand, having a "catch (Exception e)" lets exception handling be 
handled by the Action itself and allows it to show a more relevant error 
page than a global handler, but if you have an exception you wanted an 
ExceptionHandler to take care of, you're out of luck unless all Actions 
rethrow it within their "catch (Exception e)" clause.

On the other hand, using global ExceptionHandlers for non-specific
exceptions will align with with fact that non-specific exceptions are
handled the same way anyway, and forces each action to react to specific
exceptions without the "catch (Exception e)" cop-out.  That may be good 
or bad depending on how much time you and your teammates are allowed to 
spend on exception handling (and how well you sell it to your teammates).



__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message