Table of Contents

Method ThrowsAny

Namespace
Xunit
Assembly
xunit.v3.assert.dll

ThrowsAny<T>(Action)

Verifies that the exact exception or a derived exception type is thrown.

public static T ThrowsAny<T>(Action testCode) where T : Exception

Parameters

testCode Action

A delegate to the code to be tested

Returns

T

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

ThrowsAny<T>(Func<object?>)

Verifies that the exact exception or a derived exception type is thrown. Generally used to test property accessors.

public static T ThrowsAny<T>(Func<object?> testCode) where T : Exception

Parameters

testCode Func<object>

A delegate to the code to be tested

Returns

T

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown