ArgumentExceptionExtensions Class

Provides ThrowNew extension methods for ArgumentException.

public static class ArgumentExceptionExtensions

Remarks

Each public constructor of the exception type has two methods, with the parameters of the constructor. Call them on the exception type, as in ArgumentException.ThrowNew(message).

The first method returns no value. Call it as a statement.

The second method has a type parameter, which is also its return type. Call it where the code needs an expression of that type.

See also

Methods

NameDescription
ArgumentException.ThrowNew()Throws a new ArgumentException.
ArgumentException.ThrowNew(string?)Throws a new ArgumentException.
ArgumentException.ThrowNew(string?, Exception?)Throws a new ArgumentException.
ArgumentException.ThrowNew(string?, string?)Throws a new ArgumentException.
ArgumentException.ThrowNew(string?, string?, Exception?)Throws a new ArgumentException.
ArgumentException.ThrowNew<T>()Throws a new ArgumentException, where the code needs an expression of type T.
ArgumentException.ThrowNew<T>(string?)Throws a new ArgumentException, where the code needs an expression of type T.
ArgumentException.ThrowNew<T>(string?, Exception?)Throws a new ArgumentException, where the code needs an expression of type T.
ArgumentException.ThrowNew<T>(string?, string?)Throws a new ArgumentException, where the code needs an expression of type T.
ArgumentException.ThrowNew<T>(string?, string?, Exception?)Throws a new ArgumentException, where the code needs an expression of type T.

ArgumentException.ThrowNew overloads

ArgumentException.ThrowNew()

Throws a new ArgumentException.

extension(ArgumentException)
{
    public static void ThrowNew()
}

ArgumentException.ThrowNew(string?)

Throws a new ArgumentException.

extension(ArgumentException)
{
    public static void ThrowNew(string? message)
}
Parameters
message string?
The error message that explains the reason for the exception.

ArgumentException.ThrowNew(string?, Exception?)

Throws a new ArgumentException.

extension(ArgumentException)
{
    public static void ThrowNew(string? message, Exception? innerException)
}
Parameters
message string?
The error message that explains the reason for the exception.
innerException Exception?
The exception that is the cause of the current exception. If the innerException parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.

ArgumentException.ThrowNew(string?, string?)

Throws a new ArgumentException.

extension(ArgumentException)
{
    public static void ThrowNew(string? message, string? paramName)
}
Parameters
message string?
The error message that explains the reason for the exception.
paramName string?
The name of the parameter that caused the current exception.

ArgumentException.ThrowNew(string?, string?, Exception?)

Throws a new ArgumentException.

extension(ArgumentException)
{
    public static void ThrowNew(string? message, string? paramName, Exception? innerException)
}
Parameters
message string?
The error message that explains the reason for the exception.
paramName string?
The name of the parameter that caused the current exception.
innerException Exception?
The exception that is the cause of the current exception. If the innerException parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.

ArgumentException.ThrowNew<T>()

Throws a new ArgumentException, where the code needs an expression of type T.

extension(ArgumentException)
{
    public static T ThrowNew<T>()
}
Type parameters
T
The type of the expression.
Returns

T This method does not return.

ArgumentException.ThrowNew<T>(string?)

Throws a new ArgumentException, where the code needs an expression of type T.

extension(ArgumentException)
{
    public static T ThrowNew<T>(string? message)
}
Type parameters
T
The type of the expression.
Parameters
message string?
The error message that explains the reason for the exception.
Returns

T This method does not return.

ArgumentException.ThrowNew<T>(string?, Exception?)

Throws a new ArgumentException, where the code needs an expression of type T.

extension(ArgumentException)
{
    public static T ThrowNew<T>(string? message, Exception? innerException)
}
Type parameters
T
The type of the expression.
Parameters
message string?
The error message that explains the reason for the exception.
innerException Exception?
The exception that is the cause of the current exception. If the innerException parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.
Returns

T This method does not return.

ArgumentException.ThrowNew<T>(string?, string?)

Throws a new ArgumentException, where the code needs an expression of type T.

extension(ArgumentException)
{
    public static T ThrowNew<T>(string? message, string? paramName)
}
Type parameters
T
The type of the expression.
Parameters
message string?
The error message that explains the reason for the exception.
paramName string?
The name of the parameter that caused the current exception.
Returns

T This method does not return.

ArgumentException.ThrowNew<T>(string?, string?, Exception?)

Throws a new ArgumentException, where the code needs an expression of type T.

extension(ArgumentException)
{
    public static T ThrowNew<T>(string? message, string? paramName, Exception? innerException)
}
Type parameters
T
The type of the expression.
Parameters
message string?
The error message that explains the reason for the exception.
paramName string?
The name of the parameter that caused the current exception.
innerException Exception?
The exception that is the cause of the current exception. If the innerException parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.
Returns

T This method does not return.