py::builtins::assert¶
Defined in <pypp/builtins/assert.hpp>
void assert(bool expression); // 1
void assert(bool expression, std::string message); // 2
Assert an expression and throws on failure.
Assert an expression and throws on failure with given message.
py::builtins::assert asserts whether is given value is true
(usually returned from an expression) and raises
py-builtins-AssertionError on failure.
Complexity¶
Constant.
Example¶
#include <pypp/builtins/assert.hpp>
#include <pypp/builtins/print.hpp>
int main()
{
py::assert(true);
try
{
py::assert(false);
}
catch (py::AssertionError&)
{
py::print("assert failed: py::assert(false)");
}
}
Output:
assert failed: py::assert(false)