12#ifndef DOCWIRE_ERROR_H
13#define DOCWIRE_ERROR_H
15#include "core_export.h"
16#include "diagnostic_context.h"
19#include "serialization_pair.h"
20#include "source_location.h"
31#ifdef DOCWIRE_ENABLE_SHORT_MACRO_NAMES
32 #define current_location DOCWIRE_CURRENT_LOCATION
75struct DOCWIRE_CORE_EXPORT
base :
public std::exception
124 const
char*
what() const noexcept override;
135#include "stringification.h"
166template <
typename... T>
171 std::string context_string_impl()
const
173 return stringify(std::get<I>(
context));
177 type_id context_type_impl()
const noexcept
182 template <
size_t... Is>
183 std::string context_string_at(
size_t index, std::index_sequence<Is...>)
const {
184 using FuncType = std::string(
impl::*)()
const;
185 static constexpr FuncType funcs[] = { &impl::template context_string_impl<Is>... };
186 return (this->*funcs[index])();
189 template <
size_t... Is>
190 type_id context_type_at(
size_t index, std::index_sequence<Is...>)
const noexcept {
191 using FuncType =
type_id(
impl::*)()
const noexcept;
192 static constexpr FuncType funcs[] = { &impl::template context_type_impl<Is>... };
193 return (this->*funcs[index])();
223 return context_type_at(index, std::make_index_sequence<
sizeof...(T)>{});
236 return context_string_at(index, std::make_index_sequence<
sizeof...(T)>{});
Strong type representing a compile-time type identity.
Provides features for reporting and handling errors with context data using nested exceptions.
std::string diagnostic_message(const std::exception &e)
Generates a diagnostic message for the given nested exceptions chain.
The main namespace for the DocWire SDK.
basic_source_location source_location
A type that describes a location in source code. Uses a custom fallback implementation.
consteval type_id type_id_of() noexcept
Returns a compile-time strong identifier for type T.
virtual type_id context_type_id(size_t index) const noexcept=0
Get the type information of the context.
base(const source_location &location=source_location::current())
Constructs a base object with the current source location.
virtual std::string context_string(size_t index) const =0
Get the string representation of the context.
virtual size_t context_count() const noexcept=0
Get the number of context items.
source_location location
The source location where the exception was thrown.
const char * what() const noexcept override
Get the exception type.
std::tuple< T... > context
A tuple holding all context items provided when the error was created.
size_t context_count() const noexcept override
Get the number of context items.
type_id context_type_id(size_t index) const noexcept override
Get the type information of the context.
std::string context_string(size_t index) const override
Get the string representation of the context.
impl(const std::tuple< T... > &context_tuple, const source_location &location=source_location::current())
Constructs an error object from a tuple of context items.