ExceptionHelper
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
namespace Relativity.Transfer
{
internal static class ExceptionHelper
{
private static readonly object SyncRoot = new object();
private static readonly List<Type> FatalExceptionCandidates = new List<Type>(new Type[13] {
typeof(AccessViolationException),
typeof(ApplicationException),
typeof(BadImageFormatException),
typeof(DivideByZeroException),
typeof(DllNotFoundException),
typeof(EntryPointNotFoundException),
typeof(InsufficientMemoryException),
typeof(NullReferenceException),
typeof(OutOfMemoryException),
typeof(OverflowException),
typeof(SecurityException),
typeof(StackOverflowException),
typeof(ThreadAbortException)
});
private static readonly List<Type> PathExceptionCandidates = new List<Type>(new Type[3] {
typeof(DirectoryNotFoundException),
typeof(PathTooLongException),
typeof(UnauthorizedAccessException)
});
public static bool IsFatalException(Exception exception)
{
if (exception == null)
throw new ArgumentNullException("exception");
lock (SyncRoot) {
Type exceptionType = exception.GetType();
return FatalExceptionCandidates.Any((Type exceptionCandidateType) => exceptionType == exceptionCandidateType);
}
}
public static bool IsSuspectedHttpTimeoutException(Exception exception)
{
AggregateException ex = exception as AggregateException;
if (ex != null && ex.InnerException is TaskCanceledException)
return !((TaskCanceledException)ex.InnerException).CancellationToken.IsCancellationRequested;
return false;
}
public static bool IsPathException(Exception exception)
{
if (exception == null)
throw new ArgumentNullException("exception");
lock (SyncRoot) {
Type exceptionType = exception.GetType();
return PathExceptionCandidates.Any((Type exceptionCandidateType) => exceptionType == exceptionCandidateType);
}
}
}
}