Last active
August 29, 2015 14:01
-
-
Save harrybiscuit/e84a9728e66958f3fde7 to your computer and use it in GitHub Desktop.
This file contains 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 UnwrapInnerExceptionMessages(this Exception exception) | |
{ | |
var sb = new StringBuilder(); | |
if (!string.IsNullOrWhiteSpace(exception.Message)) | |
{ | |
sb.AppendLine(exception.Message); | |
} | |
if (exception.InnerException != null) | |
{ | |
sb = GetInnerExceptionMessage(sb, exception.InnerException); | |
} | |
return sb.ToString(); | |
} | |
private static StringBuilder GetInnerExceptionMessage(StringBuilder sb, Exception exception) | |
{ | |
if (!string.IsNullOrWhiteSpace(exception.Message)) | |
{ | |
sb.AppendLine(exception.Message); | |
} | |
if (exception.InnerException != null) | |
{ | |
sb = GetInnerExceptionMessage(sb, exception.InnerException); | |
} | |
return sb; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment