public static bool IsFatal(this Exception exception)
{
while (exception != null)
{
if ((exception is OutOfMemoryException && !(exception is InsufficientMemoryException)) ||
exception is ThreadAbortException ||
exception is AccessViolationException ||
exception is SEHException ||
exception is StackOverflowException)
{
return true;
}
if (exception is TypeInitializationException &&
exception is TargetInvocationException)
{
break;
}
exception = exception.InnerException;
}
return false;
}
}