Assert.ThrowsException Assert.ThrowsException Assert.ThrowsException Method

Definition

Overloads

ThrowsException<T>(Action) ThrowsException<T>(Action)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

ThrowsException<T>(Func<Object>) ThrowsException<T>(Func<Object>) ThrowsException<T>(Func<Object>)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

ThrowsException<T>(Action, String) ThrowsException<T>(Action, String)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

ThrowsException<T>(Func<Object>, String) ThrowsException<T>(Func<Object>, String) ThrowsException<T>(Func<Object>, String)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

ThrowsException<T>(Action, String, Object[]) ThrowsException<T>(Action, String, Object[])

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

ThrowsException<T>(Func<Object>, String, Object[]) ThrowsException<T>(Func<Object>, String, Object[]) ThrowsException<T>(Func<Object>, String, Object[])

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

ThrowsException<T>(Action) ThrowsException<T>(Action)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

public static T ThrowsException<T> (Action action) where T : Exception;
static member ThrowsException : Action -> 'T (requires 'T :> Exception)

Type Parameters

T

Type of exception expected to be thrown.

Parameters

action
Action Action Action

Delegate to code to be tested and which is expected to throw exception.

Returns

T T T

The exception that was thrown.

Exceptions

Thrown if action does not throws exception of type T.

ThrowsException<T>(Func<Object>) ThrowsException<T>(Func<Object>) ThrowsException<T>(Func<Object>)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

public static T ThrowsException<T> (Func<object> action) where T : Exception;
static member ThrowsException : Func<obj> -> 'T (requires 'T :> Exception)
Public Shared Function ThrowsException(Of T As Exception) (action As Func(Of Object)) As T

Type Parameters

T

Type of exception expected to be thrown.

Parameters

action
Func<Object>

Delegate to code to be tested and which is expected to throw exception.

Returns

T T T

The exception that was thrown.

Exceptions

Thrown if action does not throws exception of type T.

ThrowsException<T>(Action, String) ThrowsException<T>(Action, String)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

public static T ThrowsException<T> (Action action, string message) where T : Exception;
static member ThrowsException : Action * string -> 'T (requires 'T :> Exception)

Type Parameters

T

Type of exception expected to be thrown.

Parameters

action
Action Action Action

Delegate to code to be tested and which is expected to throw exception.

message
String String String

The message to include in the exception when action does not throws exception of type T.

Returns

T T T

The exception that was thrown.

Exceptions

Thrown if action does not throws exception of type T.

ThrowsException<T>(Func<Object>, String) ThrowsException<T>(Func<Object>, String) ThrowsException<T>(Func<Object>, String)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

public static T ThrowsException<T> (Func<object> action, string message) where T : Exception;
static member ThrowsException : Func<obj> * string -> 'T (requires 'T :> Exception)
Public Shared Function ThrowsException(Of T As Exception) (action As Func(Of Object), message As String) As T

Type Parameters

T

Type of exception expected to be thrown.

Parameters

action
Func<Object>

Delegate to code to be tested and which is expected to throw exception.

message
String String String

The message to include in the exception when action does not throws exception of type T.

Returns

T T T

The exception that was thrown.

Exceptions

Thrown if action does not throws exception of type T.

ThrowsException<T>(Action, String, Object[]) ThrowsException<T>(Action, String, Object[])

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

public static T ThrowsException<T> (Action action, string message, params object[] parameters) where T : Exception;
static member ThrowsException : Action * string * obj[] -> 'T (requires 'T :> Exception)

Type Parameters

T

Type of exception expected to be thrown.

Parameters

action
Action Action Action

Delegate to code to be tested and which is expected to throw exception.

message
String String String

The message to include in the exception when action does not throws exception of type T.

parameters
Object[]

An array of parameters to use when formatting message.

Returns

T T T

The exception that was thrown.

Exceptions

Thrown if action does not throws exception of type T.

ThrowsException<T>(Func<Object>, String, Object[]) ThrowsException<T>(Func<Object>, String, Object[]) ThrowsException<T>(Func<Object>, String, Object[])

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


AssertFailedException

if code does not throws exception or throws exception of type other than T.

public static T ThrowsException<T> (Func<object> action, string message, params object[] parameters) where T : Exception;
static member ThrowsException : Func<obj> * string * obj[] -> 'T (requires 'T :> Exception)
Public Shared Function ThrowsException(Of T As Exception) (action As Func(Of Object), message As String, ParamArray parameters As Object()) As T

Type Parameters

T

Type of exception expected to be thrown.

Parameters

action
Func<Object>

Delegate to code to be tested and which is expected to throw exception.

message
String String String

The message to include in the exception when action does not throws exception of type T.

parameters
Object[]

An array of parameters to use when formatting message.

Returns

T T T

The exception that was thrown.

Exceptions

Thrown if action does not throw exception of type T.

Applies to