You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jonathan <ja...@i-2000.com> on 2001/06/05 22:04:09 UTC

throwing Exceptions from perform()

I am seeing that I can only throw IOException and ServletException from my Action classes.  Now I was thinking about adding Exceptions to the Action class but that would make it proprietary.  I could add just Exception, but I dont want to change anything without good reason.  Can you all telll me why I am limited to these two exceptions and what you all are doing about this.  The reason is that I have my own exceptions for my app, and will need to throw them sometimes within the perform method.
Thanx
Jonathan

Re: throwing Exceptions from perform()

Posted by Jonathan <ja...@i-2000.com>.
Thanks for the idea.

----- Original Message ----- 
From: "John Raley" <jo...@moonlight.com>
To: <st...@jakarta.apache.org>
Sent: Tuesday, June 05, 2001 5:01 PM
Subject: Re: throwing Exceptions from perform()


> Hi Jonathon,
> 
> Struts calls Action.perform from the ActionServlet.  Servlets are 
> allowed to throw only these two exceptions from their service() methods 
> - so you'll need a proprietary Servlet framework as well... :^)
> 
> In my app I have a base Action class with a final perform() method.  All 
> of my actions are subclasses of this base - they implement a different, 
> protected method called doPerform() that can throw any exception.  The 
> base perform() method calls doPerform(), catches exceptions and handles 
> them appropriately.  Would this design work for you?
> 
> 
> Jonathan wrote:
> 
> > I am seeing that I can only throw IOException and ServletException 
> > from my Action classes.  Now I was thinking about adding Exceptions to 
> > the Action class but that would make it proprietary.  I could add just 
> > Exception, but I dont want to change anything without good reason.  
> > Can you all telll me why I am limited to these two exceptions and what 
> > you all are doing about this.  The reason is that I have my own 
> > exceptions for my app, and will need to throw them sometimes within 
> > the perform method.
> >
> > Thanx
> >
> > Jonathan
> >
> 
> 
> 


Re: throwing Exceptions from perform()

Posted by John Raley <jo...@moonlight.com>.
Hi Jonathon,

Struts calls Action.perform from the ActionServlet.  Servlets are 
allowed to throw only these two exceptions from their service() methods 
- so you'll need a proprietary Servlet framework as well... :^)

In my app I have a base Action class with a final perform() method.  All 
of my actions are subclasses of this base - they implement a different, 
protected method called doPerform() that can throw any exception.  The 
base perform() method calls doPerform(), catches exceptions and handles 
them appropriately.  Would this design work for you?


Jonathan wrote:

> I am seeing that I can only throw IOException and ServletException 
> from my Action classes.  Now I was thinking about adding Exceptions to 
> the Action class but that would make it proprietary.  I could add just 
> Exception, but I dont want to change anything without good reason.  
> Can you all telll me why I am limited to these two exceptions and what 
> you all are doing about this.  The reason is that I have my own 
> exceptions for my app, and will need to throw them sometimes within 
> the perform method.
>
> Thanx
>
> Jonathan
>




Re: throwing Exceptions from perform()

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 5 Jun 2001, Jonathan wrote:

> I am seeing that I can only throw IOException and ServletException
> from my Action classes.  Now I was thinking about adding Exceptions to
> the Action class but that would make it proprietary.  I could add just
> Exception, but I dont want to change anything without good reason.  
> Can you all telll me why I am limited to these two exceptions and what
> you all are doing about this.  The reason is that I have my own
> exceptions for my app, and will need to throw them sometimes within
> the perform method.
>
> Thanx Jonathan
> 

You can subclass ServletException with your own exception classes, but I
would recommend against this approach.  What it will cause is that your
user will see an ugly stack trace.  It would be better to forward control
to some error handling action (or page) that deals with this kind of a
problem more gracefully.

Craig