不能catch Fatal的exception

Clemens Vasters - Are you catching falling knives?里给了一个判断C#的exception是不是fatal的代码,可以参考参考。

public static bool IsFatal(this Exception exception)
{
    while (exception != null)
    {
        if (exception as OutOfMemoryException != null && exception as InsufficientMemoryException == null || exception as ThreadAbortException != null || 
            exception as AccessViolationException != null || exception as SEHException != null || exception as StackOverflowException != null)
        {
            return true;
        }
        else
        {
            if (exception as TypeInitializationException == null && exception as TargetInvocationException == null)
            {
                break;
            }
            exception = exception.InnerException;
        }
    }
    return false;
}
原文地址:https://www.cnblogs.com/fresky/p/2724158.html