jessyhoule icon

C# / Full Exception Message

jessyhoule | PRO | 09/24/15 01:32:39 PM UTC | 0 ⭐ | 217 👁️ | Never ⏰ | []
C# |

600 B

|

None

|

0 👍

/

0 👎

public static class ExceptionExtensions
{
    public static IEnumerable<Exception> FlatException(this Exception exception)
    {
        var innerException = exception;
 
        do
        {
            yield return innerException;
            innerException = innerException.InnerException;
        }
        while (innerException != null);
    }
 
    public static string FullExceptionMessage(this Exception exception)
    {
        var messages = exception.FlatException().Select(x => x.Message);
        var flatMessage = string.Join("\n", messages);
 
        return flatMessage;
    }
}

Comments