Feedback

Komplette Exception Message (inkl. InnerExceptions) ausgeben

Sprache: C#

Die Erweiterungsmethode für die Exception-Klasse gibt die komplette Message einer Exception und die Messages von evtl. vorhandenen InnerExceptions und den Stacktrace aus.
public static string GetCompleteMessage(this Exception exception)
        {
            Exception x = exception.InnerException;
            System.Text.StringBuilder msg = new StringBuilder(exception.Message);
            while( x != null )
            {
                msg.AppendFormat("rnrn{0}", x.Message);
                x = x.InnerException;
            }
            msg.Append("rn----Stacktrace----rn");
            msg.Append(exception.StackTrace);
            return msg.ToString();
        }
public static string GetCompleteMessage(this Exception exception)
        {
            Exception x = exception.InnerException;
            System.Text.StringBuilder msg = new StringBuilder(exception.Message);
            while( x != null )
            {
                msg.AppendFormat("rnrn{0}", x.Message);
                x = x.InnerException;
            }
            msg.Append("rn----Stacktrace----rn");
            msg.Append(exception.StackTrace);
            return msg.ToString();
        }

1 Kommentar