|
Lagrange
|
Assertions and exceptions. More...
Namespaces | |
| namespace | lagrange |
| Main namespace for Lagrange. | |
Classes | |
| struct | Error |
| Base exception for errors thrown by Lagrange functions. More... | |
| struct | BadCastError |
| An exception of this type is thrown when a lagrange::safe_cast<> fails. More... | |
| struct | ParsingError |
| An exception of this type is thrown when a parsing error occurs. More... | |
Macros | |
| #define | la_runtime_assert(...) |
| Runtime assertion check. More... | |
| #define | la_debug_assert(...) |
| Debug assertion check. More... | |
Functions | |
| LA_CORE_API void | set_breakpoint_enabled (bool enabled) |
| Sets whether to trigger a debugger breakpoint on assert failure. More... | |
| LA_CORE_API bool | is_breakpoint_enabled () |
| Returns whether to trigger a debugger breakpoint on assert failure. More... | |
| LA_CORE_API void | trigger_breakpoint () |
| Call to explicitly trigger a debugger breakpoint. | |
| LA_CORE_API bool | assertion_failed (const char *function, const char *file, unsigned int line, const char *condition, std::string_view message) |
| Called in case of an assertion failure. More... | |
Assertions and exceptions.
A failed assertion will throw an exception lagrange::Error with a specific error message, and can be caught by client code. Lagrange code uses two types of assertions:
NDEBUG is undefined). A debug assert is used to check internal code validity, and should not be triggered under any circumstance by client code. A failed debug assert indicates an error in the programmer's code, and should be fixed accordingly.Note that assert macros behave as functions, meaning they expand to a void expression and can be used in an expression such as y = (la_debug_assert(true), x).
Finally, our assertion macros can take either 1 or 2 arguments, the second argument being an optional error message. To conveniently format assertion messages with a printf-like syntax, use fmt::format:
| #define la_runtime_assert | ( | ... | ) |
#include <lagrange/utils/assert.h>
Runtime assertion check.
This check is executed for both Debug and Release configurations, and should be used, e.g., to check the validity of user-given inputs.
| condition | Condition to check at runtime. |
| message | Optional message argument. |
| #define la_debug_assert | ( | ... | ) |
#include <lagrange/utils/assert.h>
Debug assertion check.
This check is executed only for Debug configurations, and should be used as a sanity check for situations that should never arise in the program's normal execution (e.g., a doubled linked list is malformed).
| condition | Condition to check at runtime. |
| message | Optional message argument. |
| void set_breakpoint_enabled | ( | bool | enabled | ) |
#include <lagrange/utils/assert.h>
Sets whether to trigger a debugger breakpoint on assert failure.
Use this function in unit test, around lines that are supposed to throw, to avoid spurious breakpoints when running unit tests.
| [in] | enabled | True to enable breakpoint debugging, false to disable. |
| bool is_breakpoint_enabled | ( | ) |
#include <lagrange/utils/assert.h>
Returns whether to trigger a debugger breakpoint on assert failure.
Use this function in a unit test to restore previous behavior when explicitly disabling triggering debugger breakpoint.
| LA_IGNORE_NONVOID_NORETURN_WARNING_BEGIN bool assertion_failed | ( | const char * | function, |
| const char * | file, | ||
| unsigned int | line, | ||
| const char * | condition, | ||
| std::string_view | message | ||
| ) |
#include <lagrange/utils/assert.h>
Called in case of an assertion failure.
| [in] | function | Function in which the assertion failed. |
| [in] | file | File in which the assertion failed. |
| [in] | line | Line where the assertion failed. |
| [in] | condition | Assert condition that failed. |
| [in] | message | Optional error message associated with the assertion. |
foo && assertion_failed(...)