ExceptionExtensions
#Exception #Extension
public static class Extensions
{
//Usage: exception.GetInnerExceptions().Last().Message
public static IEnumerable<Exception> GetInnerExceptions(this Exception ex)
{
if (ex == null)
{
throw new ArgumentNullException();
}
var innerException = ex;
do
{
yield return innerException;
innerException = innerException.InnerException;
}
while (innerException != null);
}
}