ArgumentNullExceptionExtensions Class

Provides ThrowNew extension methods for ArgumentNullException.

public static class ArgumentNullExceptionExtensions

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 ArgumentNullException.ThrowNew(paramName).

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
ArgumentNullException.ThrowNew()Throws a new ArgumentNullException.
ArgumentNullException.ThrowNew(string?)Throws a new ArgumentNullException.
ArgumentNullException.ThrowNew(string?, Exception?)Throws a new ArgumentNullException.
ArgumentNullException.ThrowNew(string?, string?)Throws a new ArgumentNullException.
ArgumentNullException.ThrowNew<T>()Throws a new ArgumentNullException, where the code needs an expression of type T.
ArgumentNullException.ThrowNew<T>(string?)Throws a new ArgumentNullException, where the code needs an expression of type T.
ArgumentNullException.ThrowNew<T>(string?, Exception?)Throws a new ArgumentNullException, where the code needs an expression of type T.
ArgumentNullException.ThrowNew<T>(string?, string?)Throws a new ArgumentNullException, where the code needs an expression of type T.

ArgumentNullException.ThrowNew overloads

ArgumentNullException.ThrowNew()

Throws a new ArgumentNullException.

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

ArgumentNullException.ThrowNew(string?)

Throws a new ArgumentNullException.

extension(ArgumentNullException)
{
    public static void ThrowNew(string? paramName)
}
Parameters
paramName string?
The name of the parameter that caused the exception.

ArgumentNullException.ThrowNew(string?, Exception?)

Throws a new ArgumentNullException.

extension(ArgumentNullException)
{
    public static void ThrowNew(string? message, Exception? innerException)
}
Parameters
message string?
The error message that explains the reason for this exception.
innerException Exception?
The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.

ArgumentNullException.ThrowNew(string?, string?)

Throws a new ArgumentNullException.

extension(ArgumentNullException)
{
    public static void ThrowNew(string? paramName, string? message)
}
Parameters
paramName string?
The name of the parameter that caused the exception.
message string?
A message that describes the error.

ArgumentNullException.ThrowNew<T>()

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

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

T This method does not return.

ArgumentNullException.ThrowNew<T>(string?)

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

extension(ArgumentNullException)
{
    public static T ThrowNew<T>(string? paramName)
}
Type parameters
T
The type of the expression.
Parameters
paramName string?
The name of the parameter that caused the exception.
Returns

T This method does not return.

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

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

extension(ArgumentNullException)
{
    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 this exception.
innerException Exception?
The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.
Returns

T This method does not return.

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

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

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

T This method does not return.