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/06 01:04:56 UTC

Application specific Exception Handling

Hi,

I try to implement an application specific exception handling. Therefor I 
created a class that extends ExceptionHandler and my own Exception class that 
has variables for holding an error code and the filename where the exception 
occured.

When I generate a NullPointerException I generate a new object of my exception 
class an throw it. Unfortunately, in the exception handler class I only see 
an object of class Exception. So, I'm not able to get the error code and the 
filename from the exception object. When I try to cast the exception 
explicitly to my exception class I get a ClassCastException. 

How can I get an object of my own exception in the exception handler?

Regards,
Ralf.

struts-config.xml:

  <global-exceptions>
    <exception handler="de.fortu.actions.FortuExceptionHandler"
                           type="java.lang.Exception"
                           key="global.error"
                           path="/jsp/error/error.jsp"
                           scope="request" />
  </global-exceptions>

ExceptionHandler Class:

public class FortuExceptionHandler extends ExceptionHandler 
{

  public ActionForward execute (Exception ex, ExceptionConfig config,   
                               ActionMapping mapping, ActionForm formInstance, 
                                HttpServletRequest request, 
				HttpServletResponse response)
  throws ServletException 
 {
    String property = null;
    String path = null;

    if(config.getPath() != null)
      path = config.getPath();
    else
      path = mapping.getInput();

    ActionForward forward = new ActionForward(path);

    ActionError error = new ActionError("global.error.nosession");
    
    storeException (request, property, error, forward, config.getScope());
    return forward;
  }
}

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