Verifies that a block of code throws an exception of a particular type; and that the exception has an inner exception of a particular type.

Namespace:  MbUnit.Framework
Assembly:  MbUnit (in MbUnit.dll) Version: 3.3.0.0 (3.3.459.0)

Syntax

C#
public static TExpectedException Throws<TExpectedException, TExpectedInnerException>(
	Action action
)
where TExpectedException : Exception
where TExpectedInnerException : Exception
Visual Basic (Declaration)
Public Shared Function Throws(Of TExpectedException As Exception, TExpectedInnerException As Exception) ( _
	action As Action _
) As TExpectedException

Parameters

action
Type: Gallio.Common..::.Action
The action delegate to evaluate.

Type Parameters

TExpectedException
The expected type of exception.
TExpectedInnerException
The expected type of the inner exception.

Return Value

The exception that was thrown.

Remarks

If the block of code throws a subtype of the expected exception types then this method will still succeed.

This method returns the exception that was caught. To verify additional properties of the exception, such as the exception message, follow up this assertion with additional ones that verify these properties of the exception object that was returned.

Exceptions

ExceptionCondition
System..::.ArgumentNullExceptionThrown if action is null.
Gallio.Framework.Assertions..::.AssertionExceptionThrown if the verification failed unless the current AssertionFailureBehavior indicates otherwise.

See Also