dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
Exception.hpp File Reference

Exception utilities for dfx (source-location aware exceptions, nested stacks, and safe invocation helpers). More...

Include dependency graph for Exception.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dfx::Utils::Exception
 Runtime error that captures a std::source_location. More...

Macros

#define CURRENT_SOURCE_LOCATION   std::source_location::current()
 Expands to std::source_location::current().
#define THROW_NESTED(msg, ...)
 Throw an dfx::Utils::Exception nested within the currently handled exception.
#define THROW(msg, ...)
 Throw an dfx::Utils::Exception with the current source location.
#define B_ASSERT(expr, msg, ...)
 Assert-like check that throws an dfx::Utils::Exception on failure.

Typedefs

using dfx::Utils::ExceptionStack = std::vector<Exception>
 Convenience alias for a linearized nested exception chain.

Functions

template<typename T>
constexpr bool dfx::Utils::__b_assert_expr (T &&expr)
 Helper used by B_ASSERT to validate and evaluate the asserted expression.
template<typename F, typename ... Args>
requires std::invocable<F, Args...>
auto dfx::Utils::safeInvoke (std::shared_ptr< spdlog::logger > logger, F &&f, Args &&... args) noexcept
 Invoke a callable and catch/log all exceptions.
template<typename F, typename ... Args>
requires std::invocable<F, Args...>
auto dfx::Utils::safeInvoke (std::string const &loggerName, F &&f, Args &&... args) noexcept
 Convenience overload of safeInvoke using a logger name. Internally resolves the logger via spdlog::get(loggerName) and then calls the logger-pointer overload.

Detailed Description

Exception utilities for dfx (source-location aware exceptions, nested stacks, and safe invocation helpers).

Macro Definition Documentation

◆ B_ASSERT

#define B_ASSERT ( expr,
msg,
... )
Value:
do { if (!::dfx::Utils::__b_assert_expr(expr)) THROW(msg __VA_OPT__(,) __VA_ARGS__); } while (false)
#define THROW(msg,...)
Throw an dfx::Utils::Exception with the current source location.
Definition Exception.hpp:246
constexpr bool __b_assert_expr(T &&expr)
Helper used by B_ASSERT to validate and evaluate the asserted expression.
Definition Exception.hpp:171

Assert-like check that throws an dfx::Utils::Exception on failure.

Unlike assert(), this is always active (no NDEBUG semantics) and throws instead of aborting.

◆ CURRENT_SOURCE_LOCATION

#define CURRENT_SOURCE_LOCATION   std::source_location::current()

Expands to std::source_location::current().

◆ THROW

#define THROW ( msg,
... )
Value:
throw ::dfx::Utils::Exception(CURRENT_SOURCE_LOCATION, msg __VA_OPT__(,) __VA_ARGS__)
#define CURRENT_SOURCE_LOCATION
Expands to std::source_location::current().
Definition Exception.hpp:237

Throw an dfx::Utils::Exception with the current source location.

◆ THROW_NESTED

#define THROW_NESTED ( msg,
... )
Value:
static void throwNested(std::source_location location, std::format_string< Args ... > message, Args &&... args)
Throw an Exception nested within the currently handled exception.
Definition Exception.hpp:93

Throw an dfx::Utils::Exception nested within the currently handled exception.

Must be used from within a catch block.