lucid  0.0.1
Lifting-based Uncertain Control Invariant Dynamics
Loading...
Searching...
No Matches
error.h File Reference
#include <fmt/core.h>
#include <stdexcept>
#include "lucid/util/exception.h"
#include "lucid/util/logging.h"

Macros

#define LUCID_ERROR_LOG_AND_THROW(ex, msg, ...)
 Log an error message and throw an exception.
 
#define LUCID_CRITICAL_LOG_AND_THROW(ex, msg, ...)
 Log a critical message and throw an exception.
 
#define LUCID_ASSERT(condition, message)
 Assert that a condition is true, throwing an exception if it fails.
 
#define LUCID_UNREACHABLE()
 Mark code that should never be reached, throwing an exception if executed.
 
#define LUCID_CHECK_ARGUMENT(condition, argument, actual)
 Check that an argument satisfies a condition, throwing an exception if it doesn't.
 
#define LUCID_CHECK_ARGUMENT_EXPECTED(condition, argument, actual, expected)
 Check that an argument satisfies a condition with expected value information.
 
#define LUCID_CHECK_ARGUMENT_CMP(value, op, expected)
 Check that a value satisfies a comparison operation with an expected value.
 
#define LUCID_CHECK_ARGUMENT_EQ(value, expected)
 Check that a value equals an expected value.
 
#define LUCID_NOT_IMPLEMENTED()
 Throw a LucidNotImplementedException when functionality is not yet implemented.
 
#define LUCID_RUNTIME_ERROR(msg)
 Throw a LucidException with a simple message.
 
#define LUCID_RUNTIME_ERROR_FMT(msg, ...)
 Throw a LucidException with a formatted message.
 
#define LUCID_OUT_OF_RANGE(msg)
 Throw a LucidOutOfRangeException with a simple message.
 
#define LUCID_OUT_OF_RANGE_FMT(msg, ...)
 Throw a LucidOutOfRangeException with a formatted message.
 
#define LUCID_INVALID_ARGUMENT(argument, actual)
 Log an error message showing the current value and throw a LucidInvalidArgumentException.
 
#define LUCID_INVALID_ARGUMENT_EXPECTED(argument, actual, expected)
 Log an error message, showing the expected value and throw a LucidInvalidArgumentException.
 
#define LUCID_INVALID_HYPER_PARAMETER(parameter, type)
 Log an error message and throw a LucidInvalidArgumentException.
 
#define LUCID_PY_ERROR(msg)
 Log an error message and throw a LucidPyException.
 
#define LUCID_PY_ERROR_FMT(msg, ...)
 Log an error message and throw a LucidPyException.
 
#define LUCID_NOT_SUPPORTED(msg)
 Throw a LucidNotSupportedException when a functionality is not supported.
 
#define LUCID_NOT_SUPPORTED_MISSING_BUILD_DEPENDENCY(msg, dependency)
 Throw a LucidNotSupportedException when a functionality is not supported because the software was compiled without a required dependency.
 
#define LUCID_NOT_SUPPORTED_MISSING_RUNTIME_DEPENDENCY(msg, dependency)
 Throw a LucidNotSupportedException when a functionality is not supported because of a missing runtime dependency.
 

Detailed Description

Author
Room 6.030
Licence:
BSD 3-Clause License

Utilities that verify assumptions made by the program and aborts the program if those assumptions are not true. If NDEBUG is defined, most of the macro do nothing and give no explanation. It makes the program faster, but less useful for debugging.

Macro Definition Documentation

◆ LUCID_ASSERT

#define LUCID_ASSERT ( condition,
message )
Value:
do { \
if (!(condition)) { \
LUCID_CRITICAL_LOG_AND_THROW(LucidAssertionException, "Assertion `{}` failed in {}:{}: {}", condition, __FILE__, \
__LINE__, message); \
} \
} while (false)

Assert that a condition is true, throwing an exception if it fails.

This macro checks the condition and throws a LucidAssertionException with file and line information if the condition is false. Only active when NDEBUG is not defined (debug builds).

Parameters
conditionthe condition to check
messagedescriptive message explaining what the assertion checks
Exceptions
LucidAssertionExceptionif the condition is false

◆ LUCID_CHECK_ARGUMENT

#define LUCID_CHECK_ARGUMENT ( condition,
argument,
actual )
Value:
do { \
if (!(condition)) { \
LUCID_ERROR_LOG_AND_THROW(LucidInvalidArgumentException, "Invalid argument for {}: '{}'", argument, actual); \
} \
} while (false)

Check that an argument satisfies a condition, throwing an exception if it doesn't.

This macro validates function arguments and throws a LucidInvalidArgumentException if the condition is false. Only active when NCHECK is not defined.

Parameters
conditionthe condition that must be true
argumentname of the argument being checked
actualthe actual value of the argument
Exceptions
LucidInvalidArgumentExceptionif the condition is false

◆ LUCID_CHECK_ARGUMENT_CMP

#define LUCID_CHECK_ARGUMENT_CMP ( value,
op,
expected )
Value:
do { \
if (!((value)op(expected))) { \
LUCID_ERROR_LOG_AND_THROW(LucidInvalidArgumentException, \
"Invalid argument " #value " violates constraint " #value " " #op " " #expected \
" : received '{}', expected '" #op " {}'", \
value, expected); \
} \
} while (false)

Check that a value satisfies a comparison operation with an expected value.

This macro validates that value op expected is true, where op is a comparison operator. Only active when NCHECK is not defined.

Parameters
valuethe value to check
opthe comparison operator (e.g., ==, !=, <, >, <=, >=)
expectedthe expected value for comparison
Exceptions
LucidInvalidArgumentExceptionif the comparison fails

◆ LUCID_CHECK_ARGUMENT_EQ

#define LUCID_CHECK_ARGUMENT_EQ ( value,
expected )
Value:
do { \
if (!((value) == (expected))) { \
LUCID_ERROR_LOG_AND_THROW(LucidInvalidArgumentException, \
"Invalid argument " #value " violates constraint " #value " == " #expected \
" : received '{}', expected '{}'", \
value, expected); \
} \
} while (false)

Check that a value equals an expected value.

This macro validates that value == expected is true. Only active when NCHECK is not defined.

Parameters
valuethe value to check
expectedthe expected value
Exceptions
LucidInvalidArgumentExceptionif value != expected

◆ LUCID_CHECK_ARGUMENT_EXPECTED

#define LUCID_CHECK_ARGUMENT_EXPECTED ( condition,
argument,
actual,
expected )
Value:
do { \
if (!(condition)) { \
LUCID_ERROR_LOG_AND_THROW(LucidInvalidArgumentException, \
"Invalid argument for {}: received '{}', expected '{}'", argument, actual, expected); \
} \
} while (false)

Check that an argument satisfies a condition with expected value information.

This macro validates function arguments and provides both actual and expected values in the error message. Only active when NCHECK is not defined.

Parameters
conditionthe condition that must be true
argumentname of the argument being checked
actualthe actual value of the argument
expectedthe expected value or description
Exceptions
LucidInvalidArgumentExceptionif the condition is false

◆ LUCID_CRITICAL_LOG_AND_THROW

#define LUCID_CRITICAL_LOG_AND_THROW ( ex,
msg,
... )
Value:
do { \
LUCID_CRITICAL_FMT(msg, __VA_ARGS__); \
throw ::lucid::exception::ex(fmt::format(msg, __VA_ARGS__)); \
} while (false)

Log a critical message and throw an exception.

This macro logs the formatted message at CRITICAL level and then throws the specified exception.

Parameters
exthe exception type to throw (without lucid::exception:: prefix)
msgthe format string for the critical message
...arguments to format into the message
Exceptions
exthe specified exception with the formatted message

◆ LUCID_ERROR_LOG_AND_THROW

#define LUCID_ERROR_LOG_AND_THROW ( ex,
msg,
... )
Value:
do { \
LUCID_ERROR_FMT(msg, __VA_ARGS__); \
throw ::lucid::exception::ex(fmt::format(msg, __VA_ARGS__)); \
} while (false)

Log an error message and throw an exception.

This macro logs the formatted message at ERROR level and then throws the specified exception.

Parameters
exthe exception type to throw (without lucid::exception:: prefix)
msgthe format string for the error message
...arguments to format into the message
Exceptions
exthe specified exception with the formatted message

◆ LUCID_INVALID_ARGUMENT

#define LUCID_INVALID_ARGUMENT ( argument,
actual )
Value:
LUCID_ERROR_LOG_AND_THROW(LucidInvalidArgumentException, "Invalid argument for {}: {}", argument, actual)
#define LUCID_ERROR_LOG_AND_THROW(ex, msg,...)
Log an error message and throw an exception.
Definition error.h:28

Log an error message showing the current value and throw a LucidInvalidArgumentException.

Parameters
argumenthyperparameter that is invalid
actualactual value of the hyperparameter

◆ LUCID_INVALID_ARGUMENT_EXPECTED

#define LUCID_INVALID_ARGUMENT_EXPECTED ( argument,
actual,
expected )
Value:
LUCID_ERROR_LOG_AND_THROW(LucidInvalidArgumentException, "Invalid argument for {}: received '{}', expected '{}'", \
argument, actual, expected)

Log an error message, showing the expected value and throw a LucidInvalidArgumentException.

Parameters
argumenthyperparameter that is invalid
actualactual value of the hyperparameter
expectedexpected value of the hyperparameter

◆ LUCID_INVALID_HYPER_PARAMETER

#define LUCID_INVALID_HYPER_PARAMETER ( parameter,
type )
Value:
LUCID_ERROR_LOG_AND_THROW(LucidInvalidArgumentException, "Invalid hyper parameter {} of type {}", parameter, type)

Log an error message and throw a LucidInvalidArgumentException.

Used when a hyperparameter is invalid has an invalid type.

Parameters
parameterhyperparameter that is invalid
typetype of the hyperparameter

◆ LUCID_NOT_IMPLEMENTED

#define LUCID_NOT_IMPLEMENTED ( )
Value:
LUCID_ERROR_LOG_AND_THROW(LucidNotImplementedException, "{}:{} Not implemented.", __FILE__, __LINE__)

Throw a LucidNotImplementedException when functionality is not yet implemented.

This macro logs an error and throws an exception with file and line information.

Exceptions
LucidNotImplementedExceptionalways

◆ LUCID_NOT_SUPPORTED

#define LUCID_NOT_SUPPORTED ( msg)
Value:
LUCID_ERROR_LOG_AND_THROW(LucidNotSupportedException, "{} is not supported.", msg)

Throw a LucidNotSupportedException when a functionality is not supported.

Parameters
msgfunctionality or feature that is not supported

◆ LUCID_NOT_SUPPORTED_MISSING_BUILD_DEPENDENCY

#define LUCID_NOT_SUPPORTED_MISSING_BUILD_DEPENDENCY ( msg,
dependency )
Value:
LucidNotSupportedException, \
"{} is not supported because the following dependency was not included during compilation: '{}'.", msg, \
dependency)

Throw a LucidNotSupportedException when a functionality is not supported because the software was compiled without a required dependency.

Parameters
msgfunctionality or feature that is not supported
dependencymissing runtime dependency that is required for the functionality to work
Exceptions
LucidNotSupportedException

◆ LUCID_NOT_SUPPORTED_MISSING_RUNTIME_DEPENDENCY

#define LUCID_NOT_SUPPORTED_MISSING_RUNTIME_DEPENDENCY ( msg,
dependency )
Value:
LucidNotSupportedException, \
"{} is not supported because the following dependency was not found on this system: '{}'.", msg, dependency)

Throw a LucidNotSupportedException when a functionality is not supported because of a missing runtime dependency.

Parameters
msgfunctionality or feature that is not supported.
dependencymissing runtime dependency that is required for the functionality to work
Exceptions
LucidNotSupportedException

◆ LUCID_OUT_OF_RANGE

#define LUCID_OUT_OF_RANGE ( msg)
Value:
LUCID_ERROR_LOG_AND_THROW(LucidOutOfRangeException, msg, "")

Throw a LucidOutOfRangeException with a simple message.

This macro logs an error and throws an out-of-range exception.

Parameters
msgthe error message
Exceptions
LucidOutOfRangeExceptionalways

◆ LUCID_OUT_OF_RANGE_FMT

#define LUCID_OUT_OF_RANGE_FMT ( msg,
... )
Value:
LUCID_ERROR_LOG_AND_THROW(LucidOutOfRangeException, msg, __VA_ARGS__)

Throw a LucidOutOfRangeException with a formatted message.

This macro logs an error and throws an out-of-range exception with formatted arguments.

Parameters
msgthe format string for the error message
...arguments to format into the message
Exceptions
LucidOutOfRangeExceptionalways

◆ LUCID_PY_ERROR

#define LUCID_PY_ERROR ( msg)
Value:
do { \
LUCID_ERROR(msg); \
PyErr_Print(); \
throw ::lucid::exception::LucidPyException(msg); \
} while (false)

Log an error message and throw a LucidPyException.

Parameters
msgmessage to log

◆ LUCID_PY_ERROR_FMT

#define LUCID_PY_ERROR_FMT ( msg,
... )
Value:
do { \
LUCID_ERROR_FMT(msg, __VA_ARGS__); \
PyErr_Print(); \
throw ::lucid::exception::LucidPyException(fmt::format(msg, __VA_ARGS__)); \
} while (false)

Log an error message and throw a LucidPyException.

Parameters
msgerror message to log

◆ LUCID_RUNTIME_ERROR

#define LUCID_RUNTIME_ERROR ( msg)
Value:
LUCID_ERROR_LOG_AND_THROW(LucidException, msg, "")

Throw a LucidException with a simple message.

This macro logs an error and throws a general LucidException.

Parameters
msgthe error message
Exceptions
LucidExceptionalways

◆ LUCID_RUNTIME_ERROR_FMT

#define LUCID_RUNTIME_ERROR_FMT ( msg,
... )
Value:
LUCID_ERROR_LOG_AND_THROW(LucidException, msg, __VA_ARGS__)

Throw a LucidException with a formatted message.

This macro logs an error and throws a general LucidException with formatted arguments.

Parameters
msgthe format string for the error message
...arguments to format into the message
Exceptions
LucidExceptionalways

◆ LUCID_UNREACHABLE

#define LUCID_UNREACHABLE ( )
Value:
LUCID_CRITICAL_LOG_AND_THROW(LucidUnreachableException, "{}:{} Should not be reachable.", __FILE__, __LINE__)
#define LUCID_CRITICAL_LOG_AND_THROW(ex, msg,...)
Log a critical message and throw an exception.
Definition error.h:42

Mark code that should never be reached, throwing an exception if executed.

This macro throws a LucidUnreachableException with file and line information. Only active when NDEBUG is not defined (debug builds).

Exceptions
LucidUnreachableExceptionalways