public static T TraverseFor <T>([NotNull] this Exception exception) where T : class { exception = exception.ArgumentNotNull(); return(ReferenceEquals(exception.GetType(), typeof(T)) ? exception as T : exception.InnerException.TraverseFor <T>()); }
public static string GetAllMessages([NotNull] this Exception exception, char separator = ControlChars.Comma) { exception = exception.ArgumentNotNull(); IEnumerable <string> messages = exception.FromHierarchy(ex => ex.InnerException).Select(ex => ex.Message); return(string.Join(separator, messages)); }
public static bool IsCritical([NotNull] this Exception exception) { exception = exception.ArgumentNotNull(); return(exception is NullReferenceException or StackOverflowException or OutOfMemoryException or ThreadAbortException or IndexOutOfRangeException or AccessViolationException); }
public static Exception[] RetrieveAllExceptions([NotNull] Exception exception) { exception = exception.ArgumentNotNull(); var collection = new List <Exception> { exception }; if (exception.InnerException is not null) { collection.AddRange(RetrieveAllExceptions(exception.InnerException)); } return(collection.ToArray()); }
public static string[] RetrieveAllExceptionMessages([NotNull] Exception exception) { exception = exception.ArgumentNotNull(); Exception[] exceptions = RetrieveAllExceptions(exception); var messages = new string[exceptions.Length]; for (var exCount = 0; exCount < exceptions.Length; exCount++) { messages[exCount] = exceptions[exCount].Message; } return(messages); }
public static IList <(string message, string StackTrace)> GetAllMessagesWithStackTrace([NotNull] this Exception exception) { exception = exception.ArgumentNotNull(); var messages = exception.FromHierarchy(ex => ex.InnerException) .Select(ex => new { ex.Message, StackTrace = ex.StackTrace.IsNotEmpty() ? ex.StackTrace : "NONE" }) .AsEnumerable() .Select(c => (c.Message, c.StackTrace)) .ToList(); return(messages); }
public static bool IsSecurityOrCritical([NotNull] this Exception exception) { exception = exception.ArgumentNotNull(); return((exception is SecurityException) || exception.IsCritical()); }
public static bool IsFatal([NotNull] this Exception exception) { exception = exception.ArgumentNotNull(); return(exception is OutOfMemoryException); }