You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Martin Cooper <ma...@tumbleweed.com> on 2002/01/27 07:39:28 UTC

Throwing exceptions from within Struts tags

I noticed that there are two different ways in which exceptions are thrown
from within Struts tags. One way is like this:

    if (somethingBadHappened) {
        throw new JspException(messages.getMessage(...));
    }

and the other is like this:

    if (somethingBadHappened) {
        JspException e = new JspException(messages.getMessage(...));
        RequestUtils.saveException(pageContext, e);
        throw e;
    }

I'm guessing that the first is "the old way" and the second is "the new
way", and that I should use the latter when writing new code (and
potentially when updating existing code). Is this correct?

Also, is there a reason we throw JspException instead of JspTagException?

Thanks!

--
Martin Cooper



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Throwing exceptions from within Struts tags

Posted by Donnie Hale <do...@haleonline.net>.
I took advantage just this week of an exception being saved via
saveException. A place higher in the Struts call stack had turned the
exception into a "return null", so I couldn't tell why that was happening
until I pulled the exception out of the context and dumped its stack trace.

FWIW...

Donnie


> -----Original Message-----
> From: Dmitri Valdin [mailto:d.valdin@proway.de]
> Sent: Sunday, January 27, 2002 8:13 AM
> To: Struts Developers List
> Subject: Re: Throwing exceptions from within Struts tags
>
>
> The first way is not welcome for sure, since at that case the original
> exception would be lost
> (in case there was some, causing this somethingBad to happen)
> But I don't understand the reason for calling RequestUtils.saveException
> in second case. If we configure an error page in web.xml then we
> can access
> the exception just with *exception* variable which is defined on every jsp
> page.
> This error page would be a good place to log the exception as well.
> Please correct me if I am wrong.
>
> Dmitri Valdin
>
>
> > I noticed that there are two different ways in which exceptions
> are thrown
> > from within Struts tags. One way is like this:
> >
> >     if (somethingBadHappened) {
> >         throw new JspException(messages.getMessage(...));
> >     }
> >
> > and the other is like this:
> >
> >     if (somethingBadHappened) {
> >         JspException e = new JspException(messages.getMessage(...));
> >         RequestUtils.saveException(pageContext, e);
> >         throw e;
> >     }
> >
> > I'm guessing that the first is "the old way" and the second is "the new
> > way", and that I should use the latter when writing new code (and
> > potentially when updating existing code). Is this correct?
> >
> > Also, is there a reason we throw JspException instead of
> JspTagException?
> >
> > Thanks!
> >
> > --
> > Martin Cooper
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Throwing exceptions from within Struts tags

Posted by Dmitri Valdin <d....@proway.de>.
The first way is not welcome for sure, since at that case the original
exception would be lost
(in case there was some, causing this somethingBad to happen)
But I don't understand the reason for calling RequestUtils.saveException
in second case. If we configure an error page in web.xml then we can access
the exception just with *exception* variable which is defined on every jsp
page.
This error page would be a good place to log the exception as well.
Please correct me if I am wrong.

Dmitri Valdin


> I noticed that there are two different ways in which exceptions are thrown
> from within Struts tags. One way is like this:
>
>     if (somethingBadHappened) {
>         throw new JspException(messages.getMessage(...));
>     }
>
> and the other is like this:
>
>     if (somethingBadHappened) {
>         JspException e = new JspException(messages.getMessage(...));
>         RequestUtils.saveException(pageContext, e);
>         throw e;
>     }
>
> I'm guessing that the first is "the old way" and the second is "the new
> way", and that I should use the latter when writing new code (and
> potentially when updating existing code). Is this correct?
>
> Also, is there a reason we throw JspException instead of JspTagException?
>
> Thanks!
>
> --
> Martin Cooper
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Throwing exceptions from within Struts tags

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

On Sat, 26 Jan 2002, Martin Cooper wrote:

> Date: Sat, 26 Jan 2002 22:39:28 -0800
> From: Martin Cooper <ma...@tumbleweed.com>
> Reply-To: Struts Developers List <st...@jakarta.apache.org>
> To: Struts Developers List <st...@jakarta.apache.org>
> Subject: Throwing exceptions from within Struts tags
>
> I noticed that there are two different ways in which exceptions are thrown
> from within Struts tags. One way is like this:
>
>     if (somethingBadHappened) {
>         throw new JspException(messages.getMessage(...));
>     }
>
> and the other is like this:
>
>     if (somethingBadHappened) {
>         JspException e = new JspException(messages.getMessage(...));
>         RequestUtils.saveException(pageContext, e);
>         throw e;
>     }
>
> I'm guessing that the first is "the old way" and the second is "the new
> way", and that I should use the latter when writing new code (and
> potentially when updating existing code). Is this correct?
>

Yes.

> Also, is there a reason we throw JspException instead of JspTagException?
>

Historical sloth on my part.  :-)

Now that it's been done for a long time, I would not suggest changing the
habit, since existing apps might be depending on the current behavior.

> Thanks!
>
> --
> Martin Cooper
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>