Skip to content

ST::assert_handler

Michael Hansen edited this page Nov 22, 2019 · 5 revisions

string_theory assert handlers

Removed in string_theory 3.0.

Headers

#include <string_theory/assert>

Public Types

Type Definition
ST::assert_handler_t Callback object for handling asserts with custom behavior

Public Functions

Name Summary
ST::set_assert_handler Set a custom assert handler for assertion failures
ST::set_default_assert_handler Reset the default assert handler for assertion failures

Type Documentation

ST::assert_handler_t [removed]

Definition
typedef std::function<void (const char *condition_str, const char *filename, int line, const char *message)> ST::assert_handler_t

C++ function object to be called when the string_theory assert handler is called for a failed assertion. This may either hold a function pointer or a C++11 lambda expression.

The function may wish to display message to the user, as this is the message that indicates what sort of failure occurred. In addition, the C++ code which evaluated falsely is provided in condition_str, as well as the filename and line number within the string_theory source code which triggered the assertion.

It is strongly recommended to abort the process in this function. While it is not strictly necessary, failing to do so may cause parts of string_theory to execute with undefined behavior, potentially leading to other crashes or even unusual and unexpected results.

Removed in String Theory 3.0.

See also ST::set_assert_handler()


Function Documentation

ST::set_assert_handler [removed]

Signature
void ST::set_assert_handler(assert_handler_t handler) noexcept

Sets the assert handler to handler. This function will be called whenever a string_theory assertion fails for any reason.

Note that while it is not possible to compile string_theory without asserts, it is possible to handle these assertion failures with your own handler (for example, writing to a log or executing cleanup code prior to termination).

While it is possible to use this function to disable asserts in string_theory, it is not recommended as doing so may cause parts of string_theory to execute with undefined behavior, potentially leading to other crashes or even unusual and unexpected results.

Removed in String Theory 3.0.

See also ST::assert_handler_t


ST::set_default_assert_handler [removed]

Signature
void ST::set_default_assert_handler() noexcept

Reset the string_theory assert handler back to its default implementation. The default implementation simply writes the filename, line number, and message text to stderr, and then calls abort().

Removed in String Theory 3.0.