/workspaces/astro/sol3-sdk/cpp/sol3/log/except.h File Reference

Space-ng SDK: /workspaces/astro/sol3-sdk/cpp/sol3/log/except.h File Reference
Space-ng SDK
except.h File Reference
#include <boost/stacktrace.hpp>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <tl/expected.hpp>
#include <stdexcept>

Go to the source code of this file.

Classes

class  sol3::log::ExceptionBase
 
class  sol3::log::ContractViolation
 
class  sol3::log::InvalidResource
 
struct  sol3::log::details::UnwrapImpl< TWrapper, TException >
 
struct  sol3::log::details::UnwrapImpl< tl::expected< TT, TE >, TException >
 
struct  sol3::log::details::UnwrapImpl< tl::expected< TT, TE > &, TException >
 
struct  sol3::log::details::UnwrapImpl< tl::expected< TT, TE > const &, TException >
 
struct  sol3::log::details::UnwrapImpl< tl::expected< TT, TE > &&, TException >
 

Namespaces

 sol3
 
 sol3::log
 
 sol3::log::details
 

Macros

#define SOL3_THROW(TException, ...)
 
#define SOL3_UNWRAP_OR_THROW(expression, TException)
 SOL3_UNWRAP_OR_THROW(expression, TException);. More...
 
#define SOL3_UNWRAP(expression)    SOL3_UNWRAP_OR_THROW(expression, ::sol3::log::ContractViolation)
 
#define SOL3_PANIC(...)
 
#define SOL3_EXPECT(condition, ...)
 
#define SOL3_IMPL_EXPECT_OP(symbol, name_str, lhs, rhs, ...)
 
#define SOL3_EXPECT_EQ(lhs, rhs, ...)
 
#define SOL3_EXPECT_NE(lhs, rhs, ...)
 
#define SOL3_EXPECT_LE(lhs, rhs, ...)
 
#define SOL3_EXPECT_LT(lhs, rhs, ...)
 
#define SOL3_EXPECT_GE(lhs, rhs, ...)
 
#define SOL3_EXPECT_GT(lhs, rhs, ...)
 
#define SOL3_GET_OR_THROW(associative_container, key, TException, ...)
 
#define SOL3_GET(associative_container, key, ...)
 
#define SOL3_AT_OR_THROW(contiguous_container, index, TException, ...)
 
#define SOL3_AT(contiguous_container, index, ...)
 

Functions

template<class TContainer , class TKey , class TException >
auto sol3::log::details::checkedGetFromAssociativeContainer (TContainer &container, TKey const &key, char const *container_cstr, char const *key_cstr, char const *file, int line, char const *func, std::string msg) -> decltype(*(container.find(key)))
 
template<class TContainer , class TException >
auto sol3::log::details::checkedAtContiguousContainer (TContainer &container, size_t index, char const *container_cstr, char const *index_cstr, char const *file, int line, char const *func, std::string msg) -> decltype(container[index])
 

Macro Definition Documentation

◆ SOL3_AT

#define SOL3_AT (   contiguous_container,
  index,
  ... 
)
Value:
contiguous_container, \
index, \
__VA_ARGS__)
Definition: except.h:48
#define SOL3_AT_OR_THROW(contiguous_container, index, TException,...)
Definition: except.h:329

◆ SOL3_AT_OR_THROW

#define SOL3_AT_OR_THROW (   contiguous_container,
  index,
  TException,
  ... 
)
Value:
decltype((contiguous_container)), \
TException>( \
contiguous_container, \
index, \
#contiguous_container, \
#index, \
__FILE__, \
__LINE__, \
__func__, /*NOLINT*/ \
::fmt::format(__VA_ARGS__))
auto checkedAtContiguousContainer(TContainer &container, size_t index, char const *container_cstr, char const *index_cstr, char const *file, int line, char const *func, std::string msg) -> decltype(container[index])
Definition: except.h:147

◆ SOL3_EXPECT

#define SOL3_EXPECT (   condition,
  ... 
)
Value:
do { \
if (!(condition)) { \
SOL3_THROW( \
"SOL3_EXPECT({}, {})", \
#condition, \
::fmt::format(__VA_ARGS__)); \
} \
} while (0)

SOL3_EXPECT(condition, "message {}", formatable); If the given condition is false, this throws a sol3::log::ContractViolation. Used this to check pre or post conditions in your code.

◆ SOL3_EXPECT_EQ

#define SOL3_EXPECT_EQ (   lhs,
  rhs,
  ... 
)
Value:
/*NOLINT*/ \
SOL3_IMPL_EXPECT_OP(==, "EQ", lhs, rhs, __VA_ARGS__)

SOL3_EXPECT_EQ(lhs, rhs, "message {}", formatable); If it is false that lhs == rhs, throw sol3::log::ContractViolation exception..

◆ SOL3_EXPECT_GE

#define SOL3_EXPECT_GE (   lhs,
  rhs,
  ... 
)
Value:
/*NOLINT*/ \
SOL3_IMPL_EXPECT_OP(>=, "GE", lhs, rhs, __VA_ARGS__)

SOL3_EXPECT_GE(lhs, rhs, "message {}", formatable); If it is false that lhs >= rhs, throw sol3::log::ContractViolation exception..

◆ SOL3_EXPECT_GT

#define SOL3_EXPECT_GT (   lhs,
  rhs,
  ... 
)
Value:
/*NOLINT*/ \
SOL3_IMPL_EXPECT_OP(>, "GT", lhs, rhs, __VA_ARGS__)

SOL3_EXPECT_GT(lhs, rhs, "message {}", formatable); If it is false that lhs > rhs, throw sol3::log::ContractViolation exception..

◆ SOL3_EXPECT_LE

#define SOL3_EXPECT_LE (   lhs,
  rhs,
  ... 
)
Value:
/*NOLINT*/ \
SOL3_IMPL_EXPECT_OP(<=, "LE", lhs, rhs, __VA_ARGS__)

SOL3_EXPECT_LE(lhs, rhs, "message {}", formatable); If it is false that lhs <= rhs, throw sol3::log::ContractViolation exception..

◆ SOL3_EXPECT_LT

#define SOL3_EXPECT_LT (   lhs,
  rhs,
  ... 
)
Value:
/*NOLINT*/ \
SOL3_IMPL_EXPECT_OP(<, "LT", lhs, rhs, __VA_ARGS__)

SOL3_EXPECT_LT(lhs, rhs, "message {}", formatable); If it is false that lhs < rhs, throw sol3::log::ContractViolation exception..

◆ SOL3_EXPECT_NE

#define SOL3_EXPECT_NE (   lhs,
  rhs,
  ... 
)
Value:
/*NOLINT*/ \
SOL3_IMPL_EXPECT_OP(!=, "NE", lhs, rhs, __VA_ARGS__)

SOL3_EXPECT_NE(lhs, rhs, "message {}", formatable); If it is false that lhs != rhs, throw sol3::log::ContractViolation exception..

◆ SOL3_GET

#define SOL3_GET (   associative_container,
  key,
  ... 
)
Value:
associative_container, key, ::sol3::log::ContractViolation, __VA_ARGS__)
#define SOL3_GET_OR_THROW(associative_container, key, TException,...)
Definition: except.h:300

Extracts the element expression[key] from associative container expression. If such an element does not exist, ContractViolation is thrown.

example:

ApriltagTarget::Tag target_tag =
  SOL3_GET(apriltag_target.tags, id_detection.first, "").second; 

◆ SOL3_GET_OR_THROW

#define SOL3_GET_OR_THROW (   associative_container,
  key,
  TException,
  ... 
)
Value:
decltype((associative_container)), \
decltype((key)), \
TException>( \
associative_container, \
key, \
#associative_container, \
#key, \
__FILE__, \
__LINE__, \
__func__, /*NOLINT*/ \
::fmt::format(__VA_ARGS__))
auto checkedGetFromAssociativeContainer(TContainer &container, TKey const &key, char const *container_cstr, char const *key_cstr, char const *file, int line, char const *func, std::string msg) -> decltype(*(container.find(key)))
Definition: except.h:121

SOL3_GET_OR_THROW(expression, key, TException, ...);

Extracts the element expression[key] from associative container expression. If such an element does not exist, TException is thrown.

example:

ApriltagTarget::Tag target_tag =
  SOL3_GET_OR_THROW(
    apriltag_target.tags,
    id_detection.first,
    ContractViolation,
    "").second; 

◆ SOL3_IMPL_EXPECT_OP

#define SOL3_IMPL_EXPECT_OP (   symbol,
  name_str,
  lhs,
  rhs,
  ... 
)
Value:
do { \
if (!((lhs)symbol(rhs))) { \
SOL3_THROW( \
"SOL3_EXPECT_{}({} {} {})\n{}\nvs.\n{}\n{}", \
name_str, \
#lhs, \
#symbol, \
#rhs, \
lhs, \
rhs, \
::fmt::format(__VA_ARGS__)); \
} \
} while (false)

◆ SOL3_PANIC

#define SOL3_PANIC (   ...)
Value:
"SOL3_PANIC({})", \
::fmt::format(__VA_ARGS__));
#define SOL3_THROW(TException,...)
Definition: except.h:177

◆ SOL3_THROW

#define SOL3_THROW (   TException,
  ... 
)
Value:
/* NOLINT*/ \
throw TException( \
::fmt::format(__VA_ARGS__), \
__FILE__, \
__LINE__, \
(char const*)(__PRETTY_FUNCTION__))

SOL3_THROW(TException, "message {}", formatable); Use to throw a deltav exception, with the current file, line and function name attached to exception. ::fmt::format is used for the passed variatic arguments.

◆ SOL3_UNWRAP

#define SOL3_UNWRAP (   expression)     SOL3_UNWRAP_OR_THROW(expression, ::sol3::log::ContractViolation)

◆ SOL3_UNWRAP_OR_THROW

#define SOL3_UNWRAP_OR_THROW (   expression,
  TException 
)
Value:
::sol3::log::details::UnwrapImpl<decltype((expression)), TException>::impl( \
std::forward<decltype((expression))>(expression), \
__FILE__, \
__LINE__, \
(char const*)(__PRETTY_FUNCTION__), \
::fmt::format( \
"[SOL3_UNWRAP_OR_THROW] called unwrap on an invalid `{}`", \
#expression))
Definition: except.h:75

SOL3_UNWRAP_OR_THROW(expression, TException);.

Unwraps nullable type (std::optional<T>, std::expected<T,E>) and returns value of type T if bool(expression) == true. Otherwise an expression of type TException is thrown. This will print the current file, line and function name where SOL3_UNWRAP_OR_THROW is used e.g. within a component. example: /// In case of an error, #line etc. is printed of this line and not /// a #line inside of the loadImage library function. auto image = SOL3_UNWRAP_OR_THROW(loadImage(filename), InvalidResource);