Created
September 29, 2010 14:50
-
-
Save gblmarquez/602876 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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