Exception Handling ThrowNewException stack trace

Topics: Exception Handling Application Block
Jul 14, 2009 at 6:03 PM

When postHandlingAction is set to ThrowNewException for handlers like Replace or Wrap the new exception is thrown from deep inside the Enterprise Library. The stack trace look like this:

   en Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.IntentionalRethrow(Exception chainException, Exception originalException) en C:\EntLib41Src\Blocks\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicyEntry.cs:línea 81
   en Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.RethrowRecommended(Exception chainException, Exception originalException) en C:\EntLib41Src\Blocks\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicyEntry.cs:línea 99
   en Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.Handle(Exception exceptionToHandle) en C:\EntLib41Src\Blocks\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicyEntry.cs:línea 70
   en Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl.HandleException(Exception exceptionToHandle) en C:\EntLib41Src\Blocks\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicyImpl.cs:línea 79
   en Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName, ExceptionPolicyFactory policyFactory) en C:\EntLib41Src\Blocks\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicy.cs:línea 64
   en Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName) en C:\EntLib41Src\Blocks\ExceptionHandling\Src\ExceptionHandling\ExceptionPolicy.cs:línea 58
   en ExceptionHandlingQuickStart.BusinessLayer.AppService.ProcessWithWrap() en C:\EntLib41Src\Quick Starts\ExceptionHandling\CS\ExceptionHandlingQuickStart.BusinessLayer\AppService.cs:línea 133  <---- the important thing after a lot of noise

Maybe the stack trace would be cleaner if the "exceptionToHandle" parameter of the "HandleException" method could be passed by reference like this:

public void ProcessWithReplace()
{
 try
 {
  ProcessC();
 }
 catch(Exception ex)
 {
  // Invoke our policy that is responsible for making sure no secure information
  // gets out of our layer.
  //bool rethrow = ExceptionPolicy.HandleException(ex, "Replace Policy");
  bool rethrow = HandleException(ref ex, "Replace Policy");

  if (rethrow)
  {
   //throw
   throw ex;   
  }   
 }
}
private bool HandleException(ref Exception ex, string policy)
{
 ex = new ApplicationException("New message");
 return true;
}

 What do you think?

Jul 15, 2009 at 8:12 AM

Hi,

I’m not sure if this is a design decision by the ent lib team. Well try to ask them and get back to you regarding this matter.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Dec 17, 2009 at 9:09 PM

Thanks for your suggestion. However, passing it by ref won't help since the stack trace is set at the point of the throw.