shouldThrow

Used for asserting that a delegate will throw an exception.

  1. void shouldThrow(void delegate() cb, string file, size_t line)
    void
    shouldThrow
    (
    void delegate
    ()
    cb
    ,
    string file = __FILE__
    ,
    size_t line = __LINE__
    )
  2. void shouldThrow(string message, void delegate() cb, string file, size_t line)

Parameters

cb void delegate
()

The delegate that is expected to throw the exception.

file string

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

line size_t

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

Throws

If delegate does NOT throw, will throw an AssertError.

Examples

// Makes sure it throws, but does not check the message
shouldThrow(delegate() {
	throw new Exception("boom!");
});

// Will throw an exception like "AssertError@test/example.d(7): Exception was not thrown. Expected one.
shouldThrow(delegate() {

});

Meta