Assert.ThrowsException Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ThrowsException<T>(Action, String, Object[]) |
Tests whether the code specified by delegate |
ThrowsException<T>(Action) |
Tests whether the code specified by delegate |
ThrowsException<T>(Func<Object>) |
Tests whether the code specified by delegate |
ThrowsException<T>(Action, String) |
Tests whether the code specified by delegate |
ThrowsException<T>(Func<Object>, String) |
Tests whether the code specified by delegate |
ThrowsException<T>(Func<Object>, String, Object[]) |
Tests whether the code specified by delegate |
ThrowsException<T>(Action, String, Object[])
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
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;
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
.
Returns
The exception that was thrown.
Exceptions
Thrown if action
does not throws exception of type T
.
Applies to
ThrowsException<T>(Action)
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
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)
Public Shared Function ThrowsException(Of T As Exception) (action As Action) 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.
Returns
The exception that was thrown.
Exceptions
Thrown if action
does not throws exception of type T
.
Applies to
ThrowsException<T>(Func<Object>)
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
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;
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
Returns
The exception that was thrown.
Exceptions
Thrown if action
does not throws exception of type T
.
Applies to
ThrowsException<T>(Action, String)
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
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)
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
.
Returns
The exception that was thrown.
Exceptions
Thrown if action
does not throws exception of type T
.
Applies to
ThrowsException<T>(Func<Object>, String)
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
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;
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
- message
- String
The message to include in the exception when action
does not throws exception of type T
.
Returns
The exception that was thrown.
Exceptions
Thrown if action
does not throws exception of type T
.
Applies to
ThrowsException<T>(Func<Object>, String, Object[])
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
- Source:
- Assert.ThrowsException.cs
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;
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
- 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
.
Returns
The exception that was thrown.
Exceptions
Thrown if action
does not throw exception of type T
.