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();
}
Alte URL:
/snippet/komplette-exception-message-inkl-innerexceptions-ausgeben/925
Just use „Exception.ToString()“!!!!!!!!
And remember: MSDN likes you!
(http://msdn.microsoft.com/en-us/library/system.exception.tostring.aspx)