struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laine Donlan" <>
Subject RE: Declarative Exception Handling
Date Mon, 03 Dec 2001 21:12:43 GMT
Couple of comments in-line -

-----Original Message-----
From: Ted Husted []
Sent: Monday, December 03, 2001 3:15 PM
To: Struts Developers List
Subject: Re: Declarative Exception Handling

Dimitri Valdin wrote:
> Since I see no reason to define hundreds of different exceptions,
> which are very similar in their nature and are handled in a similar
> I would propose:
> *) introduce 2 base exception classes: AppException and
> which should support constructors like:
> AppException("error.password.mismatch");
> AppException("database.load", "myDatabase");
> with entries in application properties
> error.password.mismatch=<li>Invalid username and/or password, please
try again</li>
> database.load=Cannot load database from {0}
> *) extend Laine's approach with following configuration option:
> <global-exceptions>
>     <exception type="org.apache.struts.exceptions.AppException"/>
>     <exception type="org.apache.struts.exceptions.RuntimeException"
> </global-exceptions>
> - you would stay on the same page in case of all application
> - you would be forwarded to error.jsp in case of runtime exceptions
> - hadling of some particular exception can be added as well
> If the exeption key is specified, then the handling will be as Laine
has proposed.
> If no exception key is specified, then the exception.getMessage()
> will be used as a key for a lookup. exception.getValues() returns
> the array of values which can be passed to messages.getMessage():
> MessageResources messages =
> messages.getMessage(super.getMessage(), values);
> This stuff can be implemented within the basis exception class.
> If it is OK, then I can try to modify the code to introduce the

+1, but with with exception chaining for those not using 1.4

- This makes perfect sense.  I have also been toying with the idea of
- Adding another configuration property to the exceptions (i.e Handler).
- This would just be a further hook into the process allowing for more
- granular handling above page flow.  For example - if an AppException
- and was handled by a global mapping should an admin maybe get an email
- why not define a class (optionally) to perform the handling.  This
- alleviate the requirement that the controller assume how exceptions be
- for every application.

> It would mean, that Action classes should derive not from
> but from action.DispatchExceptionAction. It is exactly what we have
> done, while introducing our base action class. Personally I think,
> it is quite wise to create such base action for your project.
> You can put some additional stuff in it, which can be usefull in your
> application. ActionServlet is also a candidat for deriving from.
> For example to configure log4j.

This is probably the only recourse for now. Perhaps we can work the
support code into the base Action class, so people could extend Action
and then work this pattern into their existing base classes. Many people
are already using some variation of "doPerform".

- After first implementing this in an Action, I would question how
- deep the provided Action hierarchy should be.  As is stated -
- 'it is quite wise to create a such base action for your project' -
- but the wider the possibilities for decendance the more application
- specific base classes may be needed.  Personally, after moving away
from the
- the base action implemented handling to the controller based handling 
- our application has been cleaned up quite a bit.  It is less code that
- needs to be maintained by Actions and is purely a service provided
- by the controller.

> perhaps some time later nobody will remind old perform(), but would
> new execute() ;-)

OK by me, especially if the controller were somehow smart enough to call
one or the other if both approaches were mixed in the same application
(during a migration period).

- Isn't this kind of handled by having the base Action pass off to the
- This pretty much leaves it up to the application developer which
services to use?

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message