Tuesday, April 14, 2020

It's an extension method for an exception in C# to drill back to the root of what is wrong.

using System;
namespace MyStuff.MoreStuff
{
   public static class ExceptionExtensions
   {
      public static Exception GetOriginalException(this Exception ex)
      {
         if (ex.InnerException == null)
         {
            return ex;
         }
         return ex.InnerException.GetOriginalException();
      }
   }
}

No comments:

Post a Comment