Helper Function to get the exception details

By [)ia6l0 iii

A recursive function to loop through the Inner exceptions and format the required exception details

Code Snippet as below:

public static string GetExceptionDetails(Exception ex, bool isRecursive)
{
            StringBuilder exceptionString = new StringBuilder();
            if (isRecursive)
                exceptionString.AppendFormat(""Inner Exception {0}"",   Environment.NewLine);
            else
                exceptionString.AppendFormat("" Exception {0}"", Environment.NewLine);

            exceptionString.AppendFormat(""Exception Message:{0}{1}{2}"", Environment.NewLine, ex.Message, Environment.NewLine);
            exceptionString.AppendFormat(""Stack Trace:{0}{1}{2}"", Environment.NewLine, ex.StackTrace, Environment.NewLine);
            exceptionString.AppendFormat(""Source:{0}{1}{2}"", Environment.NewLine, ex.Source, Environment.NewLine);

            if (ex.InnerException != null)
            {
                exceptionString.Append(String.Format(""{0}{1}"", GetExceptionDetails(ex.InnerException, true), Environment.NewLine));
            }
            return exceptionString.ToString();
}

Helper Function to get the exception details  (1046 Views)