Specifies the exception to throw when the method is invoked.

Namespace:  Moq.Language
Assembly:  Moq (in Moq.dll) Version: 2.5.1.153 (2.5.1.0)

Syntax

C#
IThrowsResult Throws(
	Exception exception
)

Parameters

exception
Type: System..::.Exception
Exception instance to throw.

Examples

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

See Also