ObjectDisposedExceptionExtensions Class

Provides ThrowNew extension methods for ObjectDisposedException.

public static class ObjectDisposedExceptionExtensions

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 ObjectDisposedException.ThrowNew(objectName).

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

ObjectDisposedException.ThrowNew overloads

ObjectDisposedException.ThrowNew(string?)

extension(ObjectDisposedException)
{
    public static void ThrowNew(string? objectName)
}
Parameters
objectName string?
A string containing the name of the disposed object.

ObjectDisposedException.ThrowNew(string?, Exception?)

extension(ObjectDisposedException)
{
    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 innerException is not null, the current exception is raised in a catch block that handles the inner exception.

ObjectDisposedException.ThrowNew(string?, string?)

extension(ObjectDisposedException)
{
    public static void ThrowNew(string? objectName, string? message)
}
Parameters
objectName string?
The name of the disposed object.
message string?
The error message that explains the reason for the exception.

ObjectDisposedException.ThrowNew<T>(string?)

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

extension(ObjectDisposedException)
{
    public static T ThrowNew<T>(string? objectName)
}
Type parameters
T
The type of the expression.
Parameters
objectName string?
A string containing the name of the disposed object.
Returns

T This method does not return.

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

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

extension(ObjectDisposedException)
{
    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 innerException is not null, the current exception is raised in a catch block that handles the inner exception.
Returns

T This method does not return.

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

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

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

T This method does not return.