Exceptions
One of the most common tasks that were solved with callbacks is throwing an exception when a certain method is invoked with a given set of parameters.
To streamline the configuration of methods throwing exceptions, Moq has special constructs targeting this scenario: Throws
and ThrowsAsync
.
Both methods accept an instance of any Exception type.
Additionally, Throws
can also instantiate an exception given its type.
Thows
and ThrowsAsync
can also be used in a sequence of calls.
Throwing exceptions aware of incoming parameters
Unfortunately, Throws
and ThrowsAsync
have no overload accepting a delegate to be lazily evaluated.
The lack of such overloads makes it impossible to throw exceptions that are somehow aware of the incoming parameters.
The following statement is not supported.
The same behavior can be modeled with callbacks.
Last updated