This project is read-only.
Sometimes exceptions will not give enough information to properly diagnose the source of the error. A typical solution is to enrich the exception by wrapping it in a contextual custom exception like so:

try
{
    ....
}
catch(ArgumentException ae)
{
   throw new CustomException("Customer with name " + name + " was not found.", ae);
}

This approach is handy, but you add an additional stacktrace element, and the thrown exception might have sensitive information.

Extensions methods have been added in the GoodStuff.Diagnostics namespace. This allows for richer exception logging.

using System;
using GoodStuff.Diagnostics;

public class HelloWorld
{
   public static void Main(params string[] args)
   {
      try
      { 
           PerformWork();
      }
      catch(Exception workException)
       {
          workException.AddData(() => args);
          workException.AddData("Environment", "development");
          ExceptionHandlerModule.LogError(workException);

          ShowFriendlyErrorToTheWorld("Something went wrong.");
       } 
   }
}

You will notice extra data attached to the stacktrace in the error log, because the Exception Logger uses the same mechanism to retrieve the values of the exception.

Last edited Oct 12, 2011 at 5:14 PM by drblame, version 2

Comments

No comments yet.