You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pallavi Shetty <pa...@gmail.com> on 2007/08/02 06:05:29 UTC

Global Exceptions in Struts

Hi All,

When ever there is an error I need to handle the exceptions gracefully.
Since I'm using struts frame work I'm using global-exceptions declarative.

Here is the struts-config.xml where I have included <global-exceptions>
<global-exceptions>
<exception handler="com.hp.chrs.action.ActionExceptionHandler"
type="java.lang.Exception"
key="global.error.message"
path="/jsp/chrs_error.jsp" />
</global-exceptions>

I have written ActionExceptionHandler.java class which is the subclass of
ExceptionHandler. In execute function of this I'm logging the error then
forwarding it to chrs_error.jsp.
public ActionForward execute(Exception ex, ExceptionConfig ae,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException {
System.out.println("Inside execute of ActionExceptionHandler");
logError(ex);
//forward to the jsp
ActionForward forward =
super.execute(ex, ae, mapping, formInstance, request, response);
}
When ever an error occurs chrs_error.jsp is displayed. But it is not going
to ActionExceptionHandler.java class.

What my unerstanding is whenever error occurs it should go to
ActionExceptionHandler and then display chrs_error.jsp.

Any inputs are welcome

Thanks in Advance

Re: Global Exceptions in Struts

Posted by Paul Benedict <pb...@apache.org>.
Are you using Struts 1.3? I believe only 1.3 captures all exceptions -- 
while 1.2 captures only non-runtime exceptions.

Pallavi Shetty wrote:
> Hi All,
>
> When ever there is an error I need to handle the exceptions gracefully.
> Since I'm using struts frame work I'm using global-exceptions declarative.
>
> Here is the struts-config.xml where I have included <global-exceptions>
> <global-exceptions>
> <exception handler="com.hp.chrs.action.ActionExceptionHandler"
> type="java.lang.Exception"
> key="global.error.message"
> path="/jsp/chrs_error.jsp" />
> </global-exceptions>
>
> I have written ActionExceptionHandler.java class which is the subclass of
> ExceptionHandler. In execute function of this I'm logging the error then
> forwarding it to chrs_error.jsp.
> public ActionForward execute(Exception ex, ExceptionConfig ae,
> ActionMapping mapping,
> ActionForm formInstance,
> HttpServletRequest request,
> HttpServletResponse response)
> throws ServletException {
> System.out.println("Inside execute of ActionExceptionHandler");
> logError(ex);
> //forward to the jsp
> ActionForward forward =
> super.execute(ex, ae, mapping, formInstance, request, response);
> }
> When ever an error occurs chrs_error.jsp is displayed. But it is not going
> to ActionExceptionHandler.java class.
>
> What my unerstanding is whenever error occurs it should go to
> ActionExceptionHandler and then display chrs_error.jsp.
>
> Any inputs are welcome
>
> Thanks in Advance
>
>   

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