jessyhoule

C# / Full Exception Message

Sep 24th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. public static class ExceptionExtensions
  2. {
  3.     public static IEnumerable<Exception> FlatException(this Exception exception)
  4.     {
  5.         var innerException = exception;
  6.  
  7.         do
  8.         {
  9.             yield return innerException;
  10.             innerException = innerException.InnerException;
  11.         }
  12.         while (innerException != null);
  13.     }
  14.  
  15.     public static string FullExceptionMessage(this Exception exception)
  16.     {
  17.         var messages = exception.FlatException().Select(x => x.Message);
  18.         var flatMessage = string.Join("\n", messages);
  19.  
  20.         return flatMessage;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment