Throws(TException) Method

Moq

Collapse image Expand Image Copy image CopyHover image
Specifies the type of exception to throw when the method is invoked.

Namespace: Moq.Language
Assembly: Moq (in Moq.dll) Version: 4.0.10827.0 (4.0.0.0)

Syntax

C#
IThrowsResult Throws<TException>()
where TException : new(), Exception

Type Parameters

TException
Type of exception to instantiate and throw when the setup is matched.

Examples

This example shows how to throw an exception when the method is invoked with an empty string argument:
CopyC#
mock.Setup(x => x.Execute(""))
    .Throws<ArgumentException>();

See Also