throwAn

The phrase .should.throwA!Type (or .throwAn!Exception, depending on grammar) expects the left-hand side expression to throw an exception of the given type. The exception is caught. If no exception was thrown, .throwA itself throws a FluentException to complain. If the left-hand side threw an exception, the word .where may be used to inspect this exception further. The meaning of .throwA may be negated with .not, in which case nothing is returned.

  1. template throwA(T : Throwable)
  2. alias throwAn = throwA
    alias throwAn = throwA

Examples

auto exception = new Exception("");

/**
 * Throws: Exception
 */
void throwsException() { throw exception; }

throwsException.should.throwAn!Exception.which.should.be(exception);
throwsException.should.throwAn!Exception.which.should.not.be(null);

2.should.be(5).should.throwA!FluentException;
2.should.be(5).should.throwAn!Error.should.throwA!FluentException;

2.should.be(2).should.not.throwA!FluentException;

Meta