Skip to content

Instantly share code, notes, and snippets.

@gblmarquez
Created September 29, 2010 14:50
Show Gist options
  • Select an option

  • Save gblmarquez/602876 to your computer and use it in GitHub Desktop.

Select an option

Save gblmarquez/602876 to your computer and use it in GitHub Desktop.
public string GetExceptionMessage(Exception exception)
{
DateTime now = System.DateTime.Now;
StringBuilder error = new StringBuilder();
error.AppendLine("\nException classes:\t");
error.Append(GetExceptionTypeStack(exception));
error.AppendLine("\nException messages:\t");
error.Append(GetExceptionMessageStack(exception));
error.AppendLine("\nStack Traces:\t");
error.Append(GetExceptionCallStack(exception));
error.AppendLine("\n-------------------------------------------------------\n\n");
return error.ToString();
}
private string GetExceptionTypeStack(Exception e)
{
if (e.InnerException != null)
{
StringBuilder message = new StringBuilder();
message.AppendLine(GetExceptionTypeStack(e.InnerException));
return (message.ToString());
}
else
{
return (" " + e.GetType().ToString());
}
}
private string GetExceptionMessageStack(Exception e)
{
if (e.InnerException != null)
{
StringBuilder message = new StringBuilder();
message.AppendLine(GetExceptionMessageStack(e.InnerException));
return (message.ToString());
}
else
{
return (" " + e.Message);
}
}
private string GetExceptionCallStack(Exception e)
{
if (e.InnerException != null)
{
StringBuilder message = new StringBuilder();
message.AppendLine(GetExceptionCallStack(e.InnerException));
message.AppendLine("--- Next Call Stack:");
return (message.ToString());
}
else
{
return (e.StackTrace);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment