On Thu, 1 Nov 2001, Laine Donlan wrote:
> Date: Thu, 1 Nov 2001 16:44:06 -0500
> From: Laine Donlan <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: Struts Developers List <[EMAIL PROTECTED]>
> Subject: RE: Declarative exception handling for Action classes
>
> >> - As an alternative to passing the exception you are throwing under
> >> a particular request or session scope key, how about having your
> >> Action simply wrap the business logic exception inside a
> >> ServletException (as the root cause) and throw that? The perform
> >> method already declares "throws ServletException", and we could
> >> enhance the controller servlet to simply do its exception mapping
> >> trick on any exception thrown by the perform method.
>
> >This seems like a good idea to me. People who want the "throws
> Exception"
> >semantics can easily achieve it by subclassing Action and doing a try{}
> >catch{} in there, and then having all their actions extend the
> subclass.
>
> I guess my thinking here is if the controller is always going to do
> something like
> try{
> }catch(SevletException ser){
> ....do something with ser.getRootCause()
> }
>
> Then why not force the issue of the ServletException and allow for
> actions to throw Exception.
> If an exception is thrown that has not be mapped to an action, then it
> will be wrapped in
> ServletException and re-thrown - then it will be available for the
> normal <error-page>
> type handling by the container.
>
If we had thought of this when first designing Struts, that would have
made sense. But now, I would be ***really*** hesitant to change the
method signature for Action.perform() and potentially break everybody's
existing implementations.
However, it's still easy for an Action to throw an arbitrary exception
simply by encapsulating it:
try {
...
} catch (RemoteException e) { // Just as an example
throw new ServletException(e);
}
In Servlet 2.3 containers, the <error-page> type handling actually does
use the "root cause" exception to base its decision on, if you haven't
mapped anything to ServletException itself. The rules are spelled out in
Section 9.9.2 of the 2.3 spec. But the benefits of being able to define
this per-Action is a good reason to make the mappings configurable within
Struts itself.
>
> Laine
>
Craig
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>