Skip to content

ActionAssertions.Throw Method ​

Overloads ​

NameDescription
Throw<TException>()Asserts that the action throws an exception of the specified type.
Throw<TException>(String)Asserts that the action throws an exception of the specified type with the specified message.
Throw<TException>(String, Exception)Asserts that the action throws an exception of the specified type with the specified message and inner exception.
Throw<TException>(TException)Asserts that the action throws the exact specified exception instance.

Throw<TException>() ​

Asserts that the action throws an exception of the specified type.

c#
public ActionAssertionsChain<TException> Throw<TException>()
   where TException : Exception;

View source

Type Parameters ​

NameDescription
TExceptionThe expected exception type.

Returns ​

ActionAssertionsChain<TException>

An ActionAssertionsChain<TException> containing the thrown exception.

Throw<TException>(String) ​

Asserts that the action throws an exception of the specified type with the specified message.

c#
public ActionAssertionsChain<TException> Throw<TException>(string expectedMessage)
   where TException : Exception;

View source

Type Parameters ​

NameDescription
TExceptionThe expected exception type.

Parameters ​

NameTypeDescription
expectedMessageStringThe expected exception message.

Returns ​

ActionAssertionsChain<TException>

An ActionAssertionsChain<TException> containing the thrown exception.

Throw<TException>(String, Exception) ​

Asserts that the action throws an exception of the specified type with the specified message and inner exception.

c#
public ActionAssertionsChain<TException> Throw<TException>(string expectedMessage, Exception? expectedInnerException)
   where TException : Exception;

View source

Type Parameters ​

NameDescription
TExceptionThe expected exception type.

Parameters ​

NameTypeDescription
expectedMessageStringThe expected exception message.
expectedInnerExceptionExceptionThe expected inner exception, or null to assert no inner exception.

Returns ​

ActionAssertionsChain<TException>

An ActionAssertionsChain<TException> containing the thrown exception.

Throw<TException>(TException) ​

Asserts that the action throws the exact specified exception instance.

c#
public ActionAssertionsChain<TException> Throw<TException>(TException expected)
   where TException : Exception;

View source

Type Parameters ​

NameDescription
TExceptionThe expected exception type.

Parameters ​

NameTypeDescription
expectedTExceptionThe expected exception instance.

Returns ​

ActionAssertionsChain<TException>

An ActionAssertionsChain<TException> containing the thrown exception.