You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ralf Schneider <ml...@tapfere-schneiderleins.de> on 2004/10/08 09:11:51 UTC
How to get MyException from ExceptionHandler
I want to implement an application specific exception handling for my struts
application. So, I defined my own Exception class that extends a "normal"
Exception by an error code and the filename where the exception occured:
public class MyException extends Exception
{
private int errorCode = -1;
private String file = null;
public MyException() { super(); }
public MyException (String message, int errorCode, String file)
{
super(message);
this.errorCode = errorCode;
this.file = file;
}
public int getErrorCode () { return errorCode; }
public void setErrorCode (int errorCode) { this.errorCode = errorCode; }
public String getFile () { return file; }
public void setFile (String file) { this.file = file; }
}
I've also created my own ExceptionHandler class:
public class MyExceptionHandler extends ExceptionHandler
{
public ActionForward execute (Exception ex, ExceptionConfig config,
ActionMapping mapping, ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException
{
...
}
}
In struts-config.xml I've configured this exception handler as a
<global-exception> that should handle ALL excetions:
<global-exceptions>
<exception handler="de.fortu.actions.MyExceptionHandler"
type="java.lang.Exception"
key="global.error"
path="/jsp/error/error.jsp"
scope="request" />
</global-exceptions>
Now I generate a NullPointerException and throw my exception
object:
try
{
String str = null;
str.charAt(0);
}
catch (Exception e)
{
throw new MyException ("Test", 100, "MyAction");
}
What I see is that I run through MyExceptionHandler class, i.e. the
<global-exception> definition seems to work.
What I do NOT see is MyException class. When I stop in MyExceptionHandler and
inspect the Exception object I do not find the values I set in the catch
block before. The detailMessage says:
Error calling form action handler: metrics_onDrilldown reason: null
Any ideas what's going wrong here?
Best regards,
Ralf.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org