Partager via


Assert.ThrowsException Method

Definition

Overloads

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)

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[])

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>()

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[])

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)

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:
generic <typename T>
 where T : Exception static T ThrowsException(Func<System::Object ^> ^ action, System::String ^ message);
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

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

Exceptions

Thrown if action does not throws exception of type T.

Applies to

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:
generic <typename T>
 where T : Exception static T ThrowsException(Action ^ action, System::String ^ message);
public static T ThrowsException<T> (Action action, string message) where T : Exception;
static member ThrowsException : Action * string -> 'T (requires 'T :> Exception)
Public Shared Function ThrowsException(Of T As Exception) (action As Action, message As String) As T

Type Parameters

T

Type of exception expected to be thrown.

Parameters

action
Action

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

message
String

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

Exceptions

Thrown if action does not throws exception of type T.

Applies to

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:
generic <typename T>
 where T : Exception static T ThrowsException(Action ^ action, System::String ^ message, ... cli::array <System::Object ^> ^ parameters);
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)
Public Shared Function ThrowsException(Of T As Exception) (action As Action, message As String, ParamArray parameters As Object()) As T

Type Parameters

T

Type of exception expected to be thrown.

Parameters

action
Action

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

message
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.

Exceptions

Thrown if action does not throws exception of type T.

Applies to

ThrowsException<T>()

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:
generic <typename T>
 where T : Exception static T ThrowsException(Action ^ action);
public static T ThrowsException<T> (Action action) where T : Exception;
static member ThrowsException : Action -> 'T (requires 'T :> Exception)
Public Shared Function ThrowsException(Of T As Exception) (action As Action) As T

Type Parameters

T

Type of exception expected to be thrown.

Exceptions

Thrown if action does not throws exception of type T.

Applies to

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:
generic <typename T>
 where T : Exception static T ThrowsException(Func<System::Object ^> ^ action, System::String ^ message, ... cli::array <System::Object ^> ^ parameters);
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

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.

Exceptions

Thrown if action does not throw exception of type T.

Applies to