KASSERT  0.0.1
Karlsruhe Assertion Library
Assertions

Assertion macros provided by KAssert. More...

Macros

#define KASSERT(...)
 Assertion macro. Accepts between one and three parameters. More...
 
#define THROWING_KASSERT(...)
 Macro for throwing exceptions. Accepts between one and three parameters. More...
 
#define THROWING_KASSERT_SPECIFIED(expression, message, exception_type, ...)    KASSERT_KASSERT_HPP_THROWING_KASSERT_CUSTOM_IMPL(expression, exception_type, message, ##__VA_ARGS__)
 Macro for throwing custom exception. More...
 

Detailed Description

Assertion macros provided by KAssert.

Macro Definition Documentation

◆ KASSERT

#define KASSERT (   ...)
Value:
KASSERT_KASSERT_HPP_VARARG_HELPER_3( \
, \
__VA_ARGS__, \
KASSERT_3(__VA_ARGS__), \
KASSERT_2(__VA_ARGS__), \
KASSERT_1(__VA_ARGS__), \
ignore \
)

Assertion macro. Accepts between one and three parameters.

Assertions are enabled or disabled by setting a compile-time assertion level (-DKASSERT_ASSERTION_LEVEL=<int>). For predefined assertion levels, see Assertion levels. If an assertion is enabled and fails, the KASSERT() macro prints an expansion of the expression similar to Catch2. This process is described in Expression Expansions.

The macro accepts 1 to 3 parameters:

  1. The assertion expression (mandatory).
  2. Error message that is printed in addition to the decomposed expression (optional). The message is piped into a logger object. Thus, one can use the << operator to build the error message similar to how one would use std::cout.
  3. The level of the assertion (optional, default: kassert::assert::normal, see Assertion levels).

◆ THROWING_KASSERT

#define THROWING_KASSERT (   ...)
Value:
KASSERT_KASSERT_HPP_VARARG_HELPER_2( \
, \
__VA_ARGS__, \
THROWING_KASSERT_2(__VA_ARGS__), \
THROWING_KASSERT_1(__VA_ARGS__), \
ignore \
)

Macro for throwing exceptions. Accepts between one and three parameters.

Exceptions are only used in exception mode, which is enabled by using the CMake option -DKASSERT_EXCEPTION_MODE=On. Otherwise, the macro generates a KASSERT() with assertion level kassert::assert::kthrow (lowest level).

The macro accepts 1 to 2 parameters:

  1. Expression that causes the exception to be thrown if it evaluates to false (mandatory).
  2. Error message that is printed in addition to the decomposed expression (optional). The message is piped into a logger object. Thus, one can use the << operator to build the error message similar to how one would use std::cout.

◆ THROWING_KASSERT_SPECIFIED

#define THROWING_KASSERT_SPECIFIED (   expression,
  message,
  exception_type,
  ... 
)     KASSERT_KASSERT_HPP_THROWING_KASSERT_CUSTOM_IMPL(expression, exception_type, message, ##__VA_ARGS__)

Macro for throwing custom exception.

The macro requires at least 2 parameters:

  1. Expression that causes the exception to be thrown if it evaluates to false (mandatory).
  2. Error message that is printed in addition to the decomposed expression (optional). The message is piped into a logger object. Thus, one can use the << operator to build the error message similar to how one would use std::cout.
  3. Type of the exception to be used. The exception type must have a ctor that takes a std::string as its first argument, followed by any additional parameters passed to this macro. 4, 5, 6, ... Parameters that are forwarded to the exception type's ctor.

Any other parameter is passed to the constructor of the exception class.