shouldThrowWithMessage

Used for asserting that a expression will throw an exception with message.

void
shouldThrowWithMessage
(
T : Throwable = Exception
E
)
(
lazy E condition
,
in string message
,
in string file = __FILE__
,
in size_t line = __LINE__
)

Parameters

condition
Type: E

The expression that is expected to throw the exception.

message
Type: string

Expected message exception.

file
Type: string

The file name that the assert failed in. Should be left as default.

line
Type: size_t

The file line that the assert failed in. Should be left as default.

Throws

If expression does throw and message not expected, will throw an UnitTestException.

Examples

1 // Makes sure it throws with the message "test"
2 void withThrow(){throw new Exception("test");};
3 
4 // Will throw an exception like "checkit.exception.UnitTestException@test/example.d(7): Expression did not throw"
5 withThrow.shouldThrowWithMessage("bar");

Meta