12 #ifndef DOCWIRE_ERROR_H
13 #define DOCWIRE_ERROR_H
15 #include "core_export.h"
16 #include "diagnostic_context.h"
18 #include "serialization_pair.h"
19 #include "stringification.h"
20 #include "source_location.h"
30 #ifdef DOCWIRE_ENABLE_SHORT_MACRO_NAMES
31 #define current_location DOCWIRE_CURRENT_LOCATION
74 struct DOCWIRE_CORE_EXPORT
base :
public std::exception
93 virtual std::type_info
const&
context_type(
size_t index)
const noexcept = 0;
118 virtual const
char* what() const noexcept override;
147 template <typename... T>
152 std::string context_string_impl()
const
154 return stringify(std::get<I>(context));
158 const std::type_info& context_type_impl()
const noexcept
160 return typeid(std::get<I>(context));
163 template <
size_t... Is>
164 std::string context_string_at(
size_t index, std::index_sequence<Is...>)
const {
165 using FuncType = std::string(
impl::*)()
const;
166 static constexpr FuncType funcs[] = { &impl::template context_string_impl<Is>... };
167 return (this->*funcs[index])();
170 template <
size_t... Is>
171 const std::type_info& context_type_at(
size_t index, std::index_sequence<Is...>)
const noexcept {
172 using FuncType =
const std::type_info&(
impl::*)()
const noexcept;
173 static constexpr FuncType funcs[] = { &impl::template context_type_impl<Is>... };
174 return (this->*funcs[index])();
189 explicit impl(
const std::tuple<T...>& context_tuple,
const source_location& location = source_location::current())
190 :
base(location), context(context_tuple)
202 std::type_info
const&
context_type(
size_t index)
const noexcept
override
204 return context_type_at(index, std::make_index_sequence<
sizeof...(T)>{});
217 return context_string_at(index, std::make_index_sequence<
sizeof...(T)>{});
Provides features for reporting and handling errors with context data using nested exceptions.
A fallback implementation of source_location for compilers that do not support std::source_location.
Base class for all exceptions in the SDK.
base(const source_location &location=source_location::current())
Constructs a base object with the current source location.
virtual std::type_info const & context_type(size_t index) const noexcept=0
Get the type information of the context.
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.
Implementation of the error class for a variadic number of context items.
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.
std::type_info const & context_type(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.