utx::rt_assert is a c++ alternative of assert, with c++ exception support.
Class
class rt_assert;
Constructor
utx::rt_assert::rt_assert(bool condition, const std::string_view msg = "");
Removed constructors and methods
rt_assert() = delete; rt_assert(const utx::rt_assert &) = delete; rt_assert(const utx::rt_assert &&) = delete; utx::rt_assert & operator=(const utx::rt_assert &) = delete; utx::rt_assert & operator=(const utx::rt_assert &&) = delete;
![]() |
Note |
---|---|
|
#include <utxcpp/core.hpp> int main() { try { utx::rt_assert{true}; // pass utx::rt_assert(false); // print a short msg to std::cerr, and throw an exception } catch (std::exception & exc) { utx::printe("[utx::rt_assert]", exc.what()); } try { utx::rt_assert(2+3==7, "Does 2+3==7?"); // print a short msg to std::cerr, and throw an exception } catch (std::exception & exc) { utx::printe("[utx::rt_assert]", exc.what()); } { int x = 3; int y = x*4; utx::rt_assert(y==7, "Does y==7?"); // print a short msg to std::cerr, throw an exception, and cause a core dump. } }
Result:
utx::rt_assert(...) failed! [utx::rt_assert] utx::rt_assert(...) failed! Your condition [ ] is false! utx::rt_assert(...) failed! [utx::rt_assert] utx::rt_assert(...) failed! Your condition [ Does 2+3==7? ] is false! utx::rt_assert(...) failed! Abort trap (core dumped)