using System;
using System.Linq;
using System.Threading;
namespace Swan {
///
/// Provides extension methods for .
///
public static class ExceptionExtensions {
///
/// Returns a value that tells whether an is of a type that
/// we better not catch and ignore.
///
/// The exception being thrown.
/// if is a critical exception;
/// otherwise, .
public static Boolean IsCriticalException(this Exception @this) => @this.IsCriticalExceptionCore() || (@this.InnerException?.IsCriticalException() ?? false) || @this is AggregateException aggregateException && aggregateException.InnerExceptions.Any(e => e.IsCriticalException());
///
/// Returns a value that tells whether an is of a type that
/// will likely cause application failure.
///
/// The exception being thrown.
/// if is a fatal exception;
/// otherwise, .
public static Boolean IsFatalException(this Exception @this) => @this.IsFatalExceptionCore() || (@this.InnerException?.IsFatalException() ?? false) || @this is AggregateException aggregateException && aggregateException.InnerExceptions.Any(e => e.IsFatalException());
private static Boolean IsCriticalExceptionCore(this Exception @this) => IsFatalExceptionCore(@this) || @this is AppDomainUnloadedException || @this is BadImageFormatException || @this is CannotUnloadAppDomainException || @this is InvalidProgramException || @this is NullReferenceException;
private static Boolean IsFatalExceptionCore(this Exception @this) => @this is StackOverflowException || @this is OutOfMemoryException || @this is ThreadAbortException || @this is AccessViolationException;
}
}