Class ExceptionExtensions
Exception extensions.
Namespace: Neon.Common
Assembly: Neon.Common.dll
Syntax
public static class ExceptionExtensions
Methods
Contains<T>(Exception)
Determines whether the exception has a specified type or was triggered by an underlying exception of a specified type. This is useful for checking whether an exception has a specific inner exception or whether an AggregateException was triggered with a specific exception type.
Declaration
public static bool Contains<T>(this Exception e) where T : Exception
Parameters
Type | Name | Description |
---|---|---|
Exception | e | The exception being tested. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
T | The target exception type. |
Find(Exception, Type)
Searches an exception for an underlying exception of a specific type. This is useful for checking whether an exception has a specific inner exception or whether an AggregateException was triggered with a specific exception type.
Declaration
public static Exception Find(this Exception e, Type exceptionType)
Parameters
Type | Name | Description |
---|---|---|
Exception | e | The exception being tested. |
Type | exceptionType | The target exception type. |
Returns
Type | Description |
---|---|
Exception | The underlying exception or |
Find<T>(Exception)
Searches an exception for an underlying exception of a specific type specified as a generic type parameter. This is useful for checking whether an exception has a specific inner exception or whether an AggregateException was triggered with a specific exception type.
Declaration
public static T Find<T>(this Exception e) where T : Exception
Parameters
Type | Name | Description |
---|---|---|
Exception | e | The exception being tested. |
Returns
Type | Description |
---|---|
T | The underlying exception or |
Type Parameters
Name | Description |
---|---|
T | The target exception type. |
GetNonAggregateException(Exception)
Examines the exception passed and if it's a AggregateException then the first inner exception will be returned. This is handy when you need to log the details of the underlying exception thrown by an async operation.
Declaration
public static Exception GetNonAggregateException(this Exception e)
Parameters
Type | Name | Description |
---|---|---|
Exception | e | The exception. |
Returns
Type | Description |
---|---|
Exception | The underlying exception. |