You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by muzammil shahbaz <mu...@kapscomputing.com> on 2003/09/23 10:59:08 UTC

Exception handling in struts

Hello!

Is there any exception handling mechanism through struts? If we can
configure our global exceptions in struts-config.xml?

Any comments are welcome.

Thanks in advance.

Muzammil

Re: Exception handling in struts

Posted by Andrew Kuzmin <ku...@soft-ukraine.com>.
<snip
from="http://jakarta.apache.org/struts/userGuide/building_controller.html">

4.5 Exception Handler

You can define an ExceptionHandler to execute when an Action's execute
method throws an Exception. First, you need to subclass
org.apache.struts.action.ExceptionHandler and override the execute method.
Your execute method should process the Exception and return an ActionForward
object to tell Struts where to forward to next. Then you configure your
handler in struts-config.xml like this:

<global-exceptions>
    <exception
      key="some.key"
      type="java.io.IOException"
      handler="com.yourcorp.ExceptionHandler">
</global-exceptions>

This configuration element says that com.yourcorp.ExceptionHandler.execute
will be called when any IOException is thrown by an Action. The key is a key
into your message resources properties file that can be used to retrieve an
error message.

You can override global exception handlers by defining a handler inside an
action definition.

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.

</snip>

--
Andrew Kuzmin
http://www.java201.com


>----- Original Message -----
>From: "muzammil shahbaz" <mu...@kapscomputing.com>
>To: <st...@jakarta.apache.org>
>Sent: Tuesday, September 23, 2003 11:59 AM
>Subject: Exception handling in struts


> Hello!
>
> Is there any exception handling mechanism through struts? If we can
> configure our global exceptions in struts-config.xml?
>
> Any comments are welcome.
>
> Thanks in advance.
>
> Muzammil
>


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