Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts Users »

RE: [Error Handlers] instanceof ?

Hookom, Jacob

2003-07-15


That's what I thought from looking at the source, I'm working on a similar
bit for handling exceptions in my transaction framework, attached is the
current code I'm working on to handle parent/child/grandchild inheritance,
not fully tested.

Jacob

-----Original Message-----
From: David Graham [mailto:grahamdavid1980@(protected)]
Sent: Tuesday, July 15, 2003 12:37 PM
To: Struts Users Mailing List
Subject: Re: [Error Handlers] instanceof ?

--- "Hookom, Jacob" <Jacob.Hookom@(protected):
> Off hand, would Struts be able to catch the exception with this desired
> handler?
>
> Action throws ServiceNotFoundException
> ExceptionHandler catches ServiceException
>
> Where ServiceNotFoundException is an instance of ServiceException?

Not currently. I was thinking about improving the ExceptionHandler to
support that just today :-). It would be nice if the ExceptionHandler
acted like a global try/catch block with the same inheritance rules.

David

>
> Thanks,
> Jacob
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@(protected)
> For additional commands, e-mail: struts-user-help@(protected)
>


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@(protected)
For additional commands, e-mail: struts-user-help@(protected)

protected Map handledExceptions;
protected Collection unhandledExceptions;

public TaskKey findExceptionHandler(Class exceptionType)
{
 TaskKey key = (TaskKey) this.handledExceptions.get(exceptionType);
 if (key == null && !unhandledExceptions.contains(exceptionType))
 {
   synchronized (this.handledExceptions)
   {
     Class parent = null;
     Class closestParent = null;
     for (Iterator itr = this.handledExceptions.keySet().iterator();
       itr.hasNext();
       )
     {
       parent = (Class) itr.next();
       if (parent.isAssignableFrom(exceptionType))
       {
         if (closestParent == null || closestParent.isAssignableFrom(parent))
         {
           closestParent = parent;
         }
       }
     }

     if (closestParent != null)
     {
       key = (TaskKey) this.handledExceptions.get(closestParent);
       this.handledExceptions.put(exceptionType, key);
     }
     else
     {
       this.unhandledExceptions.add(exceptionType);
     }
     
     parent = null;
     closestParent = null;
   }
 }
 return key;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@(protected)
For additional commands, e-mail: struts-user-help@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.