Class ExceptionUtility
This utility class is designed to make exception operations more flexible and easier to work with.
Inheritance
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class ExceptionUtility
Methods
| Improve this DocCreateArgumentEmptyException(String, String)
Creates and returns a new ArgumentEmptyException initialized to the provided parameters.
Declaration
public static ArgumentEmptyException CreateArgumentEmptyException(string paramName, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | paramName | The name of the parameter that caused the exception. |
| System.String | message | A message that describes the error. |
Returns
| Type | Description |
|---|---|
| ArgumentEmptyException | A new instance of ArgumentEmptyException initialized to the provided parameters. |
CreateArgumentException(String, String)
Creates and returns a new System.ArgumentException initialized to the provided parameters.
Declaration
public static ArgumentException CreateArgumentException(string paramName, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | paramName | The name of the parameter that caused the exception. |
| System.String | message | A message that describes the error. |
Returns
| Type | Description |
|---|---|
| System.ArgumentException | A new instance of System.ArgumentException initialized to the provided parameters. |
CreateArgumentException(String, String, Exception)
Creates and returns a new System.ArgumentException initialized to the provided parameters.
Declaration
public static ArgumentException CreateArgumentException(string paramName, string message, Exception innerException)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | paramName | The name of the parameter that caused the exception. |
| System.String | message | A message that describes the error. |
| System.Exception | innerException | The exception that is the cause of the current exception. If the |
Returns
| Type | Description |
|---|---|
| System.ArgumentException | A new instance of System.ArgumentException initialized to the provided parameters. |
CreateArgumentNullException(String, String)
Creates and returns a new System.ArgumentNullException initialized to the provided parameters.
Declaration
public static ArgumentNullException CreateArgumentNullException(string paramName, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | paramName | The name of the parameter that caused the exception. |
| System.String | message | A message that describes the error. |
Returns
| Type | Description |
|---|---|
| System.ArgumentNullException | A new instance of System.ArgumentNullException initialized to the provided parameters. |
CreateArgumentOutOfRangeException(String, String)
Creates and returns a new System.ArgumentOutOfRangeException initialized to the provided parameters.
Declaration
public static ArgumentOutOfRangeException CreateArgumentOutOfRangeException(string paramName, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | paramName | The name of the parameter that caused the exception. |
| System.String | message | A message that describes the error. |
Returns
| Type | Description |
|---|---|
| System.ArgumentOutOfRangeException | A new instance of System.ArgumentOutOfRangeException initialized to the provided parameters. |
CreateTypeArgumentException(String, String)
Creates and returns a new TypeArgumentException initialized to the provided parameters.
Declaration
public static TypeArgumentException CreateTypeArgumentException(string typeParamName, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | typeParamName | The name of the type parameter that caused the exception. |
| System.String | message | A message that describes the error. |
Returns
| Type | Description |
|---|---|
| TypeArgumentException | A new instance of TypeArgumentException initialized to the provided parameters. |
CreateTypeArgumentOutOfRangeException(String, String)
Creates and returns a new TypeArgumentOutOfRangeException initialized to the provided parameters.
Declaration
public static TypeArgumentOutOfRangeException CreateTypeArgumentOutOfRangeException(string typeParamName, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | typeParamName | The name of the type parameter that caused the exception. |
| System.String | message | A message that describes the error. |
Returns
| Type | Description |
|---|---|
| TypeArgumentOutOfRangeException | A new instance of TypeArgumentOutOfRangeException initialized to the provided parameters. |
Flatten(Exception)
Flattens any inner exceptions descendant-or-self from the specified exception into an System.Collections.Generic.IEnumerable<T> sequence of exceptions.
Declaration
public static IEnumerable<Exception> Flatten(Exception exception)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Exception | exception | The exception to flatten. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<System.Exception> | An empty System.Collections.Generic.IEnumerable<T> sequence if no inner exceptions was specified; otherwise any inner exceptions rooted to the specified |
Remarks
If any inner exceptions are referenced this method will iterative flatten all of them descendant-or-self from the specified exception.
Should the exception be of the new AggregateException type introduced with .NET 4.0, the return sequence of this method will be equal to the result of the InnerExceptions property.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
Flatten(Exception, Type)
Flattens any inner exceptions descendant-or-self from the specified exception into an System.Collections.Generic.IEnumerable<T> sequence of exceptions.
Declaration
public static IEnumerable<Exception> Flatten(Exception exception, Type exceptionType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Exception | exception | The exception to flatten. |
| System.Type | exceptionType | The type of the specified |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<System.Exception> | An empty System.Collections.Generic.IEnumerable<T> sequence if no inner exceptions was referenced; otherwise any inner exceptions descendant-or-self from the specified |
Remarks
If any inner exceptions are referenced this method will iterative flatten all of them descendant-or-self from the specified exception.
Should the exception be of the new AggregateException type introduced with .NET 4.0, the return sequence of this method will be equal to the result of the InnerExceptions property.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
Parse<TResult>(IEnumerable<Exception>)
Parses the specified exceptions for a match on TResult.
Declaration
public static TResult Parse<TResult>(IEnumerable<Exception> exceptions)
where TResult : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.Exception> | exceptions | A sequence of exceptions to parse for a match on |
Returns
| Type | Description |
|---|---|
| TResult | The first matched System.Exception of |
Type Parameters
| Name | Description |
|---|---|
| TResult | The type of the System.Exception to find a match within |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
Parse<TResult>(Exception)
Parses the specified exception for a match on TResult.
Declaration
public static TResult Parse<TResult>(Exception exception)
where TResult : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| System.Exception | exception | The exception to parse for a match on |
Returns
| Type | Description |
|---|---|
| TResult | The matched |
Type Parameters
| Name | Description |
|---|---|
| TResult | The type of the |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
Refine(Exception, MethodDescriptor, Object[])
Refines the specified exception with valuable meta information extracted from the associated method and parameters.
Declaration
public static MethodWrappedException Refine(Exception exception, MethodDescriptor method, params object[] parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Exception | exception | The exception that needs to be thrown. |
| MethodDescriptor | method | The method signature containing valuable meta information. |
| System.Object[] | parameters | The optional parameters to accompany |
Returns
| Type | Description |
|---|---|
| MethodWrappedException | The specified |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
Refine(Exception, MethodBase, Object[])
Refines the specified exception with valuable meta information extracted from the associated method and parameters.
Declaration
public static MethodWrappedException Refine(Exception exception, MethodBase method, params object[] parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Exception | exception | The exception that needs to be thrown. |
| System.Reflection.MethodBase | method | The method to extract valuable meta information from. |
| System.Object[] | parameters | The optional parameters to accompany |
Returns
| Type | Description |
|---|---|
| MethodWrappedException | The specified |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
Unwrap(MethodWrappedException)
Unwraps the specified wrappedException and returns the originating exception.
Declaration
public static Exception Unwrap(MethodWrappedException wrappedException)
Parameters
| Type | Name | Description |
|---|---|---|
| MethodWrappedException | wrappedException | The wrapped exception to unwrap. |
Returns
| Type | Description |
|---|---|
| System.Exception | The originating exception from within MethodWrappedException. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|