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 TExpectedException Throws<TExpectedException>(
	Action action,
	string messageFormat,
	params Object[] messageArgs
)
where TExpectedException : Exception
Visual Basic (Declaration)
Public Shared Function Throws(Of TExpectedException As Exception) ( _
	action As Action, _
	messageFormat As String, _
	ParamArray messageArgs As Object() _
) As TExpectedException

Parameters

action
Type: Gallio.Common..::.Action
The action delegate to evaluate.
messageFormat
Type: System..::.String
The custom assertion message format, or null if none.
messageArgs
Type: array< System..::.Object >[]()[]
The custom assertion message arguments, or null if none.

Type Parameters

TExpectedException
The expected type of exception.

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 action is null.
Gallio.Framework.Assertions..::.AssertionExceptionThrown if the verification failed unless the current AssertionFailureBehavior indicates otherwise.

See Also