ExceptionHandlingException "Unable to handle exception: \"\"."

Topics: Exception Handling Application Block
Mar 25, 2009 at 12:51 PM
Edited Mar 25, 2009 at 3:13 PM
I have picked up a project from someone else and don't know much about the ExceptionHandling block. The problem I have is that genuine exceptions are being masked by an ExceptionHandlingException with a message of "Unable to handle exception: \"\".". I have looked at the config and cant see anything immediately wrong with it. The code was taken from a production environment where I assume this was working.

This is the config:

<exceptionHandlingConfiguration>
  <xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null">
    <enterpriseLibrary.exceptionHandlingSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/exceptionhandling">
      <exceptionPolicies>
        <exceptionPolicy name="MyPolicy">
          <exceptionTypes>
            <exceptionType name="Exception" type="System.Exception, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow">
              <exceptionHandlers>
                <exceptionHandler xsi:type="LoggingExceptionHandlerData" name="Logging Handler" defaultLogCategory="Trace" defaultEventID="100" defaultSeverity="Error" defaultTitle="My Exception Logging" formatterTypeName="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null" minimumPriority="0" />
                <exceptionHandler xsi:type="CustomHandlerData" name="Custom Handler" type="MyCustomExceptionHandeler, CommonFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
              </exceptionHandlers>
            </exceptionType>
          </exceptionTypes>
        </exceptionPolicy>
      </exceptionPolicies>
    </enterpriseLibrary.exceptionHandlingSettings>
  </xmlSerializerSection>
</exceptionHandlingConfiguration>

and this is the calling code:

catch (Exception ex)
                    {
                        bool rethrow = ExceptionPolicy.HandleException(ex, "MyPolicy");
                        if(rethrow)
                            throw ex;
                    }


this is the stack trace:


Stack Trace:

[ExceptionHandlingException: Unable to handle exception: "".]
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.ExecuteHandlerChain(Exception ex, Guid handlingInstanceID) +353
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.Handle(Exception ex) +125
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception ex) +163
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception ex, String policyName, ConfigurationContext configurationContext) +156
   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception ex, String policyName) +52
   Coverpoint.WillisBloodstock.UI.Quote.Quote_Pre_2nd_EyeCheck.OnInit(EventArgs e) in C:\Development\Coverpoint.Bloodstock\Coverpoint.WillisBloodstock.Web\UI\Quote\Quote_Pre_2nd_EyeCheck.aspx.cs:217
   System.Web.UI.Control.InitRecursive(Control namingContainer) +321
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +692
 




what else do i need to do? any ideas what is going wrong here?


appreciate any help.
Mar 26, 2009 at 1:42 AM
You only copied the configuration file?  What about the custom handler class? (MyCustomExceptionHandeler, CommonFramework).  If you also copied the custom handler, what does it perform specifically?  Make sure also that you have a reference to Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging assembly.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Mar 26, 2009 at 10:40 AM
Hi Sarah

Thanks for the response.. you're right, the problem is with the custom handler, if i comment it out from the config file everything is fine. The custom handler only overrides the method with three parameters, not the base method that gets called so i'm still not sure what the problem is. Not really sure what the original author was trying to do, but here is their code, if you can shed any light that is appreciated:

    public class MyExceptionHandeler : ExceptionHandler
    {
        public override Exception HandleException(Exception exception, string policyName, Guid correlationID)
        {
            string sExceptionType = exception.GetType().ToString();
            switch (sExceptionType.ToLower())
            {
                case "system.dividebyzeroexception":
                    return new MyException("You are trying to Divide a number by Zero", exception);

                case "":
                    return exception;
            }
            return new MyException("First Initialize the Object before Using", exception);
        }

        public override void Initialize(ConfigurationView configurationView)
        {
        }
    }

Mar 26, 2009 at 10:55 AM
 Looking at it I expect it to execute this line:
 return new MyException("First Initialize the Object before Using", exception);
But the error message you're getting doesn't suggest that it does.  Could you debug and step in to the HandleException method of the custom handler? So we know which specific line did it
execute. 

By the way,  what do you specifically want to do with your exceptions?  Do you need this custom handler?  If yes, just modify it the way you want it to handle exceptions.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Mar 26, 2009 at 11:12 AM
hi sarah, ive got to the bottom of it - the custom handler wasnt getting called at all - some numpty had renamed a dll and not updated the config. it's a shame the enterprise library couldn't have been a little more help, two days wasted, but there you go! thanks alot for your help, you got me looking in the right place, much appreciated :)
Mar 26, 2009 at 11:18 AM
I think if you opened it using the configuration editor, it will be able to tell you that it can't find the type for that custom handler.  Anyway, glad to be of help.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com