expectThrows

Asserts that the expression throws the specified throwable.

T
expectThrows
(
T : Throwable = Exception
E
)
(
lazy E expression
,
lazy string msg = null
,
string file = __FILE__
,
size_t line = __LINE__
)

Return Value

Type: T

the caught throwable

Throws

AssertException otherwise

Examples

1 import std.exception : enforce;
2 
3 auto exception = expectThrows(enforce(false));
4 
5 assertEquals("Enforcement failed", exception.msg);
auto exception = expectThrows!AssertException(expectThrows(42));

assertEquals("expected <Exception> was not thrown", exception.msg);

Meta