Exception handlers

Topics: Exception Handling Application Block
Apr 18, 2011 at 2:32 PM

An easy question that I have not been able to find a definitive answer to. When I define an exception policy I can associate one or more handlers for that policy. I am assuming that for that policy all of the handlers will be invoked each time an exception listed occurs?

For WCF you can "wrap" an exception with FaultException<T>. The client catches the FaultException<T> and gets the detail which is an exception of type T. Is there any way for the client to catch all FaultException regardless of the generic type and at the same type get the detail which will be the type thrown if desired?

Thank you.

 

Apr 19, 2011 at 1:03 AM

I probably misunderstood your first question but I'll just explain how it works.  Let's say you have an exception policy which handles two exceptions, ArgumentException and ApplicationException. 

ApplicationPolicy  ->  ArgumentException    ->   LoggingExceptionHandler
                                            ->   ReplaceHandler (replace with ApplicationException)
                         
                   ->  ApplicationException ->   LoggingExceptionHandler
                                            ->   WrapHandler (wrap in a custom exception)

If an ArgumentException is caught and you apply code so that the "ApplicationPolicy" exception policy handles that, that exception will be logged (LoggingExceptionHandler) and it will get replaced with an ApplicationException (ReplaceHandler).  That's it, procesing stops and you'll get an ApplicationException, not a custom exception.  It won't try to recursively handle exceptions. 

On your second question, you can catch the non-generic FaultException but then you'll still need to cast it to the specific FaultException<T> so as to be able to get the details.  I'm not aware of any way to obtain the details without getting it from the generic version of the FaultException.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Apr 19, 2011 at 1:53 PM

I think you misunderstood my question but I think you still answered it.

I was mainly concerned that the exception would get logged AND replaced. Not that since it was replaced it would get logged and wrapped after being replaced.

Thank you.

From: AvanadeSupport [email removed]
Sent: Monday, April 18, 2011 8:04 PM
To: rkevinburton@charter.net
Subject: Re: Exception handlers [entlib:254350]

From: AvanadeSupport

I probably misunderstood your first question but I'll just explain how it works. Let's say you have an exception policy which handles two exceptions, ArgumentException and ApplicationException.

ApplicationPolicy  ->  ArgumentException    ->   LoggingExceptionHandler
                                            ->   ReplaceHandler (replace with ApplicationException)
                         
                   ->  ApplicationException ->   LoggingExceptionHandler
                                            ->   WrapHandler (wrap in a custom exception)

If an ArgumentException is caught and you apply code so that the "ApplicationPolicy" exception policy handles that, that exception will be logged (LoggingExceptionHandler) and it will get replaced with an ApplicationException (ReplaceHandler). That's it, procesing stops and you'll get an ApplicationException, not a custom exception. It won't try to recursively handle exceptions.

On your second question, you can catch the non-generic FaultException but then you'll still need to cast it to the specific FaultException<T> so as to be able to get the details. I'm not aware of any way to obtain the details without getting it from the generic version of the FaultException.

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com