public static bool IsFatal()

in iothub/device/src/Common/Fx.cs [96:146]


        public static bool IsFatal(Exception ex)
        {
            while (ex != null)
            {
                // FYI, CallbackException is-a FatalException
                if (ex is FatalException
#if !NET451
                    || ex is OutOfMemoryException
#else
                    || (ex is OutOfMemoryException
                        && !(ex is InsufficientMemoryException))
                    || ex is ThreadAbortException
                    || ex is AccessViolationException
#endif
                    || ex is SEHException)
                {
                    return true;
                }

                // These exceptions aren't themselves fatal, but since the CLR uses them to wrap other exceptions,
                // we want to check to see whether they've been used to wrap a fatal exception.  If so, then they
                // count as fatal.
                if (ex is TypeInitializationException
                    || ex is TargetInvocationException)
                {
                    ex = ex.InnerException;
                }
                else if (ex is AggregateException aggEx)
                {
                    // AggregateExceptions have a collection of inner exceptions, which may themselves be other
                    // wrapping exceptions (including nested AggregateExceptions).  Recursively walk this
                    // hierarchy.  The (singular) InnerException is included in the collection.
                    ReadOnlyCollection<Exception> innerExceptions = aggEx.InnerExceptions;
                    foreach (Exception innerException in innerExceptions)
                    {
                        if (IsFatal(innerException))
                        {
                            return true;
                        }
                    }

                    break;
                }
                else
                {
                    break;
                }
            }

            return false;
        }