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:[EMAIL PROTECTED]
Sent: Tuesday, July 15, 2003 12:37 PM
To: Struts Users Mailing List
Subject: Re: [Error Handlers] instanceof ?

--- "Hookom, Jacob" <[EMAIL PROTECTED]> wrote:
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


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

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to