Exception constraints can be used to verify that your code throws the correct exceptions.
AssertThrows
AssertThrows succeeds if the exception thrown by the call is of the supplied type (or one of its subtypes).
AssertThrows(std::logic_error, myObject.a_method(42));
Making Assertions on the Thrown Exceptions
If AssertThrows succeeds, it will store the thrown exception so that you can make more detailed assertions on it.
AssertThrows(std::logic_error, myObject.a_method(42));
Assert::That(LastException<std::logic_error>().what(), Is().Containing("logic failure"));
The LastException<> is available in the scope of the call to AssertThrows. An exception is not available between specs in order to avoid the result of one spec contaminating another.
No comments