web 2.0

Useful Exception Extension Method – Get Full Stack Trace With Recursion

Hi,

Tonight a useful Exception Extension Method in order to Get Full Stack Trace With Inner Exception Recursion.

public static class ExceptionExtensions
{
    public static String ToFullStackTrace(this Exception ex, Int32 count)
    {
        if (ex == null)
            throw new ArgumentException();
        StringBuilder sb = new StringBuilder();
        sb.Append(ex.StackTrace);

        int innerReferences = 0;
        Exception inner = ex.InnerException;
        while (inner != null && innerReferences < count)
        {
            sb.Insert(0, inner.StackTrace);
            inner = inner.InnerException;
            innerReferences++;
        }
        return sb.ToString();
    }
    public static String ToFullStackTrace(this Exception ex)
    {
        return ex.ToFullStackTrace(50);
    }
}

Hope this Help’s!



Views(1811)

kick it on DotNetKicks.com

Share/Save/Bookmark Subscribe

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

C#

Comments

Add comment


 

biuquote
Loading



Technorati Profile