You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Leandro Melo <lt...@yahoo.com.br> on 2004/08/10 03:06:51 UTC

Exception handler question

Hi,
i'm now starting to deal with exception in my
application.

So far, i haven't used Struts exception handling
alternatives, so, i'm very new at that.

After some reading i have a few questions (please mark
True of False on my sentences , naturally comments are
welcome!).

    * It seems to me that Struts has a very nice way
to deal with Exceptions, and i actually should use
that.

    * Is it nice to have locals exceptions handlers
for my Action, or i should just have a few (or one)
global Exception Handler?

    * When do i need to override ExceptionHandler? I
couldn't figure it out a situation where it's needed
(maybe if i want to do some special logs for every
exceptions??? ).

    * Here's an advice from jakarta: " A common use of
ExceptionHandlers is to configure one for
java.lang.Exception so it's called for any exception
and log the exception to some data store.".
      Is it really a nice strategy???


Well, i think this is it! I'd appreciate some comments.

=====
_________________________________
Leandro Terra C. Melo
Eng. de Controle e Automação - UFMG

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Exception handler question

Posted by Sebastian Ho <se...@bii.a-star.edu.sg>.
Oh..should hit myself for not seeing this.

I just throws the exception in my execute(). I was confused because I
forgotten execute is called by struts and not by me. Thats y i was
wondering don't I have to catch it somewhere else in order for my codes
to compile.

Thanks Craig

Sebastian Ho

On Tue, 2004-08-24 at 10:04, Craig McClanahan wrote:
> On 24 Aug 2004 09:56:14 +0800, Sebastian Ho
> <se...@bii.a-star.edu.sg> wrote:
> > Hi
> > 
> > If I plan to use global exception in struts, how do I actually throw the
> > exception in my codes in order for the struts exception to kick in? I am
> > little confused here how it works because if I do not catch my
> > exceptions, it won't even compile. I am refering to non-runtime
> > exception here.
> > 
> > Sebastian Ho
> > 
> 
> Which method are you using in your Action classes?  If it is the
> perform() method from Struts 1.0, there is no "throws" clause there,
> so you will definite get compile errors if you try to throw one. 
> Change over to the execute() method (and be sure you're using Struts
> 1.1, of course), and you will be able to throw any exception that you
> like.
> 
> Craig
> 
> 
> > 
> > 
> > 
> > On Tue, 2004-08-10 at 10:59, Kishore Senji wrote:
> > > On Mon, 9 Aug 2004 22:06:51 -0300 (ART), Leandro Melo
> > > <lt...@yahoo.com.br> wrote:
> > > > Hi,
> > > > i'm now starting to deal with exception in my
> > > > application.
> > > >
> > > > So far, i haven't used Struts exception handling
> > > > alternatives, so, i'm very new at that.
> > > >
> > > > After some reading i have a few questions (please mark
> > > > True of False on my sentences , naturally comments are
> > > > welcome!).
> > > >
> > > >    * It seems to me that Struts has a very nice way
> > > > to deal with Exceptions, and i actually should use
> > > > that.
> > >
> > > True !
> > >
> > > >
> > > >    * Is it nice to have locals exceptions handlers
> > > > for my Action, or i should just have a few (or one)
> > > > global Exception Handler?
> > >
> > > True (If required) Having LocalException Handlers will give the
> > > functionality of handling a particular exception differently, if
> > > required.
> > >
> > > >
> > > >    * When do i need to override ExceptionHandler? I
> > > > couldn't figure it out a situation where it's needed
> > > > (maybe if i want to do some special logs for every
> > > > exceptions??? ).
> > > >
> > >
> > > One scenario might be to handle NestedException, You might override
> > > execute(Exception ex, ExceptionConfig config, ActionMapping mapping,
> > > ActionForm form, HttpServletRequest request, HttpServletResponse
> > > response) method of ExceptionHandler to show error messages for all
> > > the exceptiosn.
> > >
> > > >    * Here's an advice from jakarta: " A common use of
> > > > ExceptionHandlers is to configure one for
> > > > java.lang.Exception so it's called for any exception
> > > > and log the exception to some data store.".
> > > >      Is it really a nice strategy???
> > > >
> > >
> > > Well Sure, first a local ExceptionHandler is invoked if found,
> > > otherwise, the global
> > > ExceptionHandlers are searched, if not, the Exception's superclass are
> > > searched in a similar fashion. So, declaring a handler for
> > > java.lang.Exception, will always be there for you as a default handler
> > > for any type of Exception, if you haven't defined a specific handler
> > > for that particular exception.
> > >
> > >
> > > > Well, i think this is it! I'd appreciate some comments.
> > > >
> > > > =====
> > > > _________________________________
> > > > Leandro Terra C. Melo
> > > > Eng. de Controle e Automação - UFMG
> > > >
> > > > __________________________________________________
> > > > Do You Yahoo!?
> > > > Tired of spam?  Yahoo! Mail has the best spam protection around
> > > > http://mail.yahoo.com
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > > For additional commands, e-mail: user-help@struts.apache.org
> > > >
> > > >
> > >
> > > Thanks,
> > >
> > > Kishore Senji.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> > 
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Exception handler question

Posted by Craig McClanahan <cr...@gmail.com>.
On 24 Aug 2004 09:56:14 +0800, Sebastian Ho
<se...@bii.a-star.edu.sg> wrote:
> Hi
> 
> If I plan to use global exception in struts, how do I actually throw the
> exception in my codes in order for the struts exception to kick in? I am
> little confused here how it works because if I do not catch my
> exceptions, it won't even compile. I am refering to non-runtime
> exception here.
> 
> Sebastian Ho
> 

Which method are you using in your Action classes?  If it is the
perform() method from Struts 1.0, there is no "throws" clause there,
so you will definite get compile errors if you try to throw one. 
Change over to the execute() method (and be sure you're using Struts
1.1, of course), and you will be able to throw any exception that you
like.

Craig


> 
> 
> 
> On Tue, 2004-08-10 at 10:59, Kishore Senji wrote:
> > On Mon, 9 Aug 2004 22:06:51 -0300 (ART), Leandro Melo
> > <lt...@yahoo.com.br> wrote:
> > > Hi,
> > > i'm now starting to deal with exception in my
> > > application.
> > >
> > > So far, i haven't used Struts exception handling
> > > alternatives, so, i'm very new at that.
> > >
> > > After some reading i have a few questions (please mark
> > > True of False on my sentences , naturally comments are
> > > welcome!).
> > >
> > >    * It seems to me that Struts has a very nice way
> > > to deal with Exceptions, and i actually should use
> > > that.
> >
> > True !
> >
> > >
> > >    * Is it nice to have locals exceptions handlers
> > > for my Action, or i should just have a few (or one)
> > > global Exception Handler?
> >
> > True (If required) Having LocalException Handlers will give the
> > functionality of handling a particular exception differently, if
> > required.
> >
> > >
> > >    * When do i need to override ExceptionHandler? I
> > > couldn't figure it out a situation where it's needed
> > > (maybe if i want to do some special logs for every
> > > exceptions??? ).
> > >
> >
> > One scenario might be to handle NestedException, You might override
> > execute(Exception ex, ExceptionConfig config, ActionMapping mapping,
> > ActionForm form, HttpServletRequest request, HttpServletResponse
> > response) method of ExceptionHandler to show error messages for all
> > the exceptiosn.
> >
> > >    * Here's an advice from jakarta: " A common use of
> > > ExceptionHandlers is to configure one for
> > > java.lang.Exception so it's called for any exception
> > > and log the exception to some data store.".
> > >      Is it really a nice strategy???
> > >
> >
> > Well Sure, first a local ExceptionHandler is invoked if found,
> > otherwise, the global
> > ExceptionHandlers are searched, if not, the Exception's superclass are
> > searched in a similar fashion. So, declaring a handler for
> > java.lang.Exception, will always be there for you as a default handler
> > for any type of Exception, if you haven't defined a specific handler
> > for that particular exception.
> >
> >
> > > Well, i think this is it! I'd appreciate some comments.
> > >
> > > =====
> > > _________________________________
> > > Leandro Terra C. Melo
> > > Eng. de Controle e Automação - UFMG
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam?  Yahoo! Mail has the best spam protection around
> > > http://mail.yahoo.com
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> >
> > Thanks,
> >
> > Kishore Senji.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Exception handler question

Posted by Sebastian Ho <se...@bii.a-star.edu.sg>.
Hi

If I plan to use global exception in struts, how do I actually throw the
exception in my codes in order for the struts exception to kick in? I am
little confused here how it works because if I do not catch my
exceptions, it won't even compile. I am refering to non-runtime
exception here.

Sebastian Ho


On Tue, 2004-08-10 at 10:59, Kishore Senji wrote:
> On Mon, 9 Aug 2004 22:06:51 -0300 (ART), Leandro Melo
> <lt...@yahoo.com.br> wrote:
> > Hi,
> > i'm now starting to deal with exception in my
> > application.
> > 
> > So far, i haven't used Struts exception handling
> > alternatives, so, i'm very new at that.
> > 
> > After some reading i have a few questions (please mark
> > True of False on my sentences , naturally comments are
> > welcome!).
> > 
> >    * It seems to me that Struts has a very nice way
> > to deal with Exceptions, and i actually should use
> > that.
> 
> True !
> 
> > 
> >    * Is it nice to have locals exceptions handlers
> > for my Action, or i should just have a few (or one)
> > global Exception Handler?
> 
> True (If required) Having LocalException Handlers will give the
> functionality of handling a particular exception differently, if
> required.
> 
> > 
> >    * When do i need to override ExceptionHandler? I
> > couldn't figure it out a situation where it's needed
> > (maybe if i want to do some special logs for every
> > exceptions??? ).
> > 
> 
> One scenario might be to handle NestedException, You might override
> execute(Exception ex, ExceptionConfig config, ActionMapping mapping,
> ActionForm form, HttpServletRequest request, HttpServletResponse
> response) method of ExceptionHandler to show error messages for all
> the exceptiosn.
> 
> >    * Here's an advice from jakarta: " A common use of
> > ExceptionHandlers is to configure one for
> > java.lang.Exception so it's called for any exception
> > and log the exception to some data store.".
> >      Is it really a nice strategy???
> > 
> 
> Well Sure, first a local ExceptionHandler is invoked if found,
> otherwise, the global
> ExceptionHandlers are searched, if not, the Exception's superclass are
> searched in a similar fashion. So, declaring a handler for
> java.lang.Exception, will always be there for you as a default handler
> for any type of Exception, if you haven't defined a specific handler
> for that particular exception.
> 
> 
> > Well, i think this is it! I'd appreciate some comments.
> > 
> > =====
> > _________________________________
> > Leandro Terra C. Melo
> > Eng. de Controle e Automação - UFMG
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> > 
> > 
> 
> Thanks,
> 
> Kishore Senji.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Exception handler question

Posted by Kishore Senji <ks...@gmail.com>.
On Mon, 9 Aug 2004 22:06:51 -0300 (ART), Leandro Melo
<lt...@yahoo.com.br> wrote:
> Hi,
> i'm now starting to deal with exception in my
> application.
> 
> So far, i haven't used Struts exception handling
> alternatives, so, i'm very new at that.
> 
> After some reading i have a few questions (please mark
> True of False on my sentences , naturally comments are
> welcome!).
> 
>    * It seems to me that Struts has a very nice way
> to deal with Exceptions, and i actually should use
> that.

True !

> 
>    * Is it nice to have locals exceptions handlers
> for my Action, or i should just have a few (or one)
> global Exception Handler?

True (If required) Having LocalException Handlers will give the
functionality of handling a particular exception differently, if
required.

> 
>    * When do i need to override ExceptionHandler? I
> couldn't figure it out a situation where it's needed
> (maybe if i want to do some special logs for every
> exceptions??? ).
> 

One scenario might be to handle NestedException, You might override
execute(Exception ex, ExceptionConfig config, ActionMapping mapping,
ActionForm form, HttpServletRequest request, HttpServletResponse
response) method of ExceptionHandler to show error messages for all
the exceptiosn.

>    * Here's an advice from jakarta: " A common use of
> ExceptionHandlers is to configure one for
> java.lang.Exception so it's called for any exception
> and log the exception to some data store.".
>      Is it really a nice strategy???
> 

Well Sure, first a local ExceptionHandler is invoked if found,
otherwise, the global
ExceptionHandlers are searched, if not, the Exception's superclass are
searched in a similar fashion. So, declaring a handler for
java.lang.Exception, will always be there for you as a default handler
for any type of Exception, if you haven't defined a specific handler
for that particular exception.


> Well, i think this is it! I'd appreciate some comments.
> 
> =====
> _________________________________
> Leandro Terra C. Melo
> Eng. de Controle e Automação - UFMG
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

Thanks,

Kishore Senji.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org