InvalidOperationExceptionExtensions Class

Provides ThrowNew extension methods for InvalidOperationException.

public static class InvalidOperationExceptionExtensions

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

InvalidOperationException.ThrowNew overloads

InvalidOperationException.ThrowNew()

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

InvalidOperationException.ThrowNew(string?)

extension(InvalidOperationException)
{
    public static void ThrowNew(string? message)
}
Parameters
message string?
The message that describes the error.

InvalidOperationException.ThrowNew(string?, Exception?)

extension(InvalidOperationException)
{
    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 (Nothing in Visual Basic), the current exception is raised in a catch block that handles the inner exception.

InvalidOperationException.ThrowNew<T>()

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

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

T This method does not return.

InvalidOperationException.ThrowNew<T>(string?)

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

extension(InvalidOperationException)
{
    public static T ThrowNew<T>(string? message)
}
Type parameters
T
The type of the expression.
Parameters
message string?
The message that describes the error.
Returns

T This method does not return.

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

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

extension(InvalidOperationException)
{
    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 (Nothing in Visual Basic), the current exception is raised in a catch block that handles the inner exception.
Returns

T This method does not return.