xtd 0.2.0
Loading...
Searching...
No Matches

◆ throws_

#define throws_ (   exception_t,
  ... 
)

#include <xtd.tunit/include/xtd/tunit/assert.h>

Asserts that the statement throws a particular exception when called.

Template Parameters
exception_tThe exception type that must be throw.
Parameters
statementThe statement that verify.
messageAn optional user message to display if the assertion fails. This message can be seen in the unit test results.
Remarks
Contains information about current file and current line.
Can be used with xtd::tunit::assert, xtd::tunit::assume and xtd::tunit::valid classes.
Examples
std::vector<int> v1 = {1, 2, 3, 4};
xtd::tunit::assert::throws_(std::out_of_range, [&] {v1.at(5);}); // test ok.
xtd::tunit::assert::throws_(std::out_of_range, [&] {v1.at(2);}, "User message..."); // test error.
xtd::tunit::assume::throws_(std::out_of_range, [&] {v1.at(5);}); // test ok.
xtd::tunit::assume::throws_(std::out_of_range, [&] {v1.at(2);}, "User message..."); // test error.
xtd::tunit::valid::throws_(std::out_of_range, [&] {v1.at(5);}); // test ok.
xtd::tunit::valid::throws_(std::out_of_range, [&] {v1.at(2);}, "User message..."); // test error.