Created
February 8, 2013 08:43
-
-
Save Nilzor/4737502 to your computer and use it in GitHub Desktop.
A handy Exception extension class exposing GetAsString()
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 static class ExceptionExtensions | |
| { | |
| public static string GetAsString(this Exception ex) | |
| { | |
| StringBuilder sb = new StringBuilder(); | |
| AppendDefaultExceptionString(ex, sb); | |
| return sb.ToString(); | |
| } | |
| private static void AppendDefaultExceptionString(this Exception ex, StringBuilder sb) | |
| { | |
| sb.AppendLine(ex.GetType().ToString()); | |
| sb.AppendLine(ex.Message); | |
| sb.AppendLine(ex.StackTrace); | |
| sb.AppendLine(); | |
| if (ex.InnerException != null) | |
| { | |
| sb.AppendLine("---Inner exception: "); | |
| AppendDefaultExceptionString(ex.InnerException, sb); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment