Skip to content

Instantly share code, notes, and snippets.

@harrybiscuit
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrybiscuit/e84a9728e66958f3fde7 to your computer and use it in GitHub Desktop.
Save harrybiscuit/e84a9728e66958f3fde7 to your computer and use it in GitHub Desktop.
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