struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hubert Rabago <jakartau...@yahoo.com>
Subject RE: Exception Handling in Action objects
Date Mon, 03 Nov 2003 18:10:08 GMT
I'm just trying to get other ideas for exception handling, specifically within
Struts Action objects.

I'm working on two different projects at the moment, both of which handle
exceptions differently, and I'm wondering if one is better than the 
other and if I should propose changes for improvements for one of them.
I see the advantage of leaving common exceptions to ExceptionHandler objects
(yes, I'm aware of the action-specific one, thanks to this list), but the
individual Action objects lose part of their control, too, and so I'm wondering
how others at handling it.

In project A, there's a lot of "catch (Exception e)" which allows the action to
just show its own input page for whatever error it gets, but it loses the
ExceptionHandler capability (I have a fix for that but it ain't pretty).

If I miss a particular exception during testing and someone else encounters it,
with a "catch (Exception e)" in each Action object, at least the user can proceed
from the same page.  With an common ExceptionHandler, the user gets a common
error page which seems less friendly.

Opinions, anyone?

--- David Friedman <humble@ix.netcom.com> wrote:
> Hubert,
> 
> In struts v1.1 and newer, you can setup local exception handlers for an
> action such as:
> 
> <action ...>
> ...
> <exception .... />
> <exception .... />
> <exception .... />
> ...
> </action>
> 
> You sound like you're worried about a phenomenal number of exceptions.  It
> sounds a little like overkill for exceptions.
> 
> Regards,
> David
> 
> -----Original Message-----
> From: Hubert Rabago [mailto:jakartauser@yahoo.com]
> Sent: Monday, November 03, 2003 12:41 PM
> To: struts-user@jakarta.apache.org
> Subject: Exception Handling in Action objects
> 
> 
> 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
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
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