Re: How do I use a Customised Struts ExceptionHandler ??

2002-10-10 Thread chuckcavaness

In the struts-config.xml file, add an  
element to this action. You can also put it in the 
 section if more than one action will 
utilize this exception handler. 

Here's an example action mapping using an exception 
element:

 

   
   
  

Notice the  element. The handler attribute is 
the fully-qualified class name of your handler. As you 
have done, it must extend the default handler. The type 
attribute specifes the fully-qualified exception class 
for when you want to call this exception handler. You 
can put "java.lang.Exception" if you want this handler 
to process all exceptions thrown during this Action.

Hope that helps,
Chuck
> I have a class that extents the default struts ExceptionHandler ( see below).
> 
> Now, when an exception occurs in the 'Action' class..., how do i make 
> sure that
> the 'execute()' in 'MyExceptionHandler' is executed instaed of the 
> default ExceptionHandler?
> 
> 
> public class MyExceptionHandler extends ExceptionHandler {
> 
>   private MyChainedException tCE = null;=
> 
>   /**
>* Constructor for an external message 
>* @param tce of type MyChainedException
>*
>*/
>   public MyExceptionHandler(MyChainedException tce) {
>   this.tCE = tce; 
>   
>   }
>   public ActionForward execute(Exception ex,
>   ExceptionConfig config,
>   ActionMapping mapping,
>   ActionForm formInstance,
>   HttpServletRequest request,
>   HttpServletResponse response)
>  throws ServletException {
>   ActionForward forward = null;
>   ActionError error = null;
>   String property = null;
> 
>   /* Get the path for the forward either from the exception element
>* or from the input attribute.
>*/
>   String path = null;
>   if (config.getPath() != null) {
>path = config.getPath();
>   }else{
> path = mapping.getInput();
>   }
>   // Construct the forward object
>   forward = new ActionForward(path);
> 
>   /* Figure out what type of exception has been thrown. The Struts
>* AppException is not being used in this example.
>*/
>   if( tCE instanceof MyChainedException) {
> // This is the specialized behavior
>
> Throwable t = tCE.getCause();
> String messageKey = t.getClass().getName();
> error = new ActionError( messageKey );
>
>   }
> 
>   // Store the ActionError into the proper scope
>   // The storeException method is defined in the parent class
>   storeException(request, property, error, forward, =
> config.getScope());
> 
>   return forward;
> }
> 
> 
> }
> 
> 
> --
> To unsubscribe, e-mail:   
> For additional commands, e-mail: 
> 

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




How do I use a Customised Struts ExceptionHandler ??

2002-10-10 Thread Gudla, Shailender X -ND

I have a class that extents the default struts ExceptionHandler ( see below).

Now, when an exception occurs in the 'Action' class..., how do i make 
sure that
the 'execute()' in 'MyExceptionHandler' is executed instaed of the 
default ExceptionHandler?


public class MyExceptionHandler extends ExceptionHandler {

private MyChainedException tCE = null;=

/**
 * Constructor for an external message 
 * @param tce of type MyChainedException
 *
 */
public MyExceptionHandler(MyChainedException tce) {
this.tCE = tce; 

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

  /* Get the path for the forward either from the exception element
   * or from the input attribute.
   */
  String path = null;
  if (config.getPath() != null) {
   path = config.getPath();
  }else{
path = mapping.getInput();
  }
  // Construct the forward object
  forward = new ActionForward(path);

  /* Figure out what type of exception has been thrown. The Struts
   * AppException is not being used in this example.
   */
  if( tCE instanceof MyChainedException) {
// This is the specialized behavior
   
Throwable t = tCE.getCause();
String messageKey = t.getClass().getName();
error = new ActionError( messageKey );
   
  }

  // Store the ActionError into the proper scope
  // The storeException method is defined in the parent class
  storeException(request, property, error, forward, =
config.getScope());

  return forward;
}


}


--
To unsubscribe, e-mail:   
For additional commands, e-mail: