Class ExceptionExtensions
Inherited Members
Namespace: Estrelica.Utility
Assembly: Estrelica.Utility.dll
Syntax
public static class ExceptionExtensions
Methods
ContainsAllMessageText(Exception, params string[])
Returns true if all of the messageTextSubstrings are found in the hierarchy of flattened exceptions. If any messageTextSubstrings are null or empty strings, the result will always be false.
Declaration
public static bool ContainsAllMessageText(this Exception ex, params string[] messageTextSubstrings)
Parameters
Exception ex |
string[] messageTextSubstrings |
Returns
bool |
Remarks
Substring comparison is not case sensitive.
ContainsAnyMessageText(Exception, params string[])
Returns true if any exceptions in the flattened hierachy have a Message containing any of the strings in messageTextSubstrings (excluding nulls and empty strings)
Declaration
public static bool ContainsAnyMessageText(this Exception ex, params string[] messageTextSubstrings)
Parameters
Exception ex |
string[] messageTextSubstrings |
Returns
bool |
Remarks
Substring comparison is not case sensitive.
ContainsMessageText(Exception, string)
Returns true if any exceptions in the flattened hierarchy have a Message containing messageTextSubstring.
Declaration
public static bool ContainsMessageText(this Exception ex, string messageTextSubstring)
Parameters
Exception ex |
string
messageTextSubstring
Substring to locate in any of the exception's flattened hierarchy of Messages. If null or empty string, the result will always be false. |
Returns
bool |
Remarks
Substring comparison is not case sensitive.
FindException(Exception, Func<Exception, bool>)
Returns true if any exceptions in the flattened hiearchy satisfy the predicate.
Declaration
public static bool FindException(this Exception ex, Func<Exception, bool> predicate)
Parameters
Exception ex |
Func<Exception, bool> predicate |
Returns
bool |
FindException<E>(Exception, Func<Exception, bool>)
Returns the first Exception of type E found in the exception's flattened hierarchy
Declaration
public static Exception FindException<E>(this Exception exception, Func<Exception, bool> predicate = null) where E : Exception
Parameters
Exception
exception
The root exception |
Func<Exception, bool>
predicate
The predicate to be evaluated |
Returns
Exception |
Type Parameters
E
Exception type to find |
Remarks
Note that the predicate will be evaluated on the original exception as well if it is of type E
Flatten(Exception)
Flattens a hierarchy of exceptions into an IEnumerable for easy checking of a specific exception that might be buried in InnerException, InnerExceptions, and their flattened results as well.
Declaration
public static IEnumerable<Exception> Flatten(this Exception ex)
Parameters
Exception ex |
Returns
IEnumerable<Exception>
IEnumerable<Exception> |
Remarks
Note that the original starting exception (if not null) will be returned as the first item in the iteration. If you only want the contained exceptions, use ".Skip(1)" on the results