Verifies that a block of code throws an 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 Exception Throws(
	Type expectedExceptionType,
	Action action
)
Visual Basic (Declaration)
Public Shared Function Throws ( _
	expectedExceptionType As Type, _
	action As Action _
) As Exception

Parameters

expectedExceptionType
Type: System..::.Type
The expected exception type.
action
Type: Gallio.Common..::.Action
The action delegate to evaluate.

Return Value

The exception that was thrown.

Remarks

If the block of code throws a subtype of the expected exception type 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 expectedExceptionType or action is null.
Gallio.Framework.Assertions..::.AssertionExceptionThrown if the verification failed unless the current AssertionFailureBehavior indicates otherwise.

See Also