kaycxx-assert
C++ assertion library
Loading...
Searching...
No Matches
assert_not_throw

Asserts that a function does not throw, or does not throw a specific exception/message combination.

The one-argument form fails on any thrown exception. The typed forms only fail when the thrown exception type and message match the unexpected condition; other exceptions are intentionally allowed by those overloads.

#include <regex>
#include <stdexcept>
using namespace kaycxx::assert;
int main() {
assert_not_throw([] {
auto value = 40 + 2;
(void)value;
});
assert_not_throw<std::runtime_error>(
[] { throw std::runtime_error{"Temporary failure"}; },
"Fatal failure"
);
assert_not_throw<std::runtime_error>(
[] { throw std::runtime_error{"Warning 17"}; },
std::regex{"Fatal [0-9]+"}
);
}
Includes the complete public assertion API.
Assertion functions and related types.
Definition assert.hpp:15

Use the typed overloads when one specific error must not happen, but unrelated errors are not part of this assertion.