17#ifndef TOOLBOX_UTIL_EXCEPTION_HPP
18#define TOOLBOX_UTIL_EXCEPTION_HPP
23inline namespace util {
32 explicit Exception(std::error_code ec = std::error_code());
33 Exception(
int err,
const std::error_category& ecat);
34 Exception(std::error_code ec, std::string_view what);
35 Exception(
int err,
const std::error_category& ecat, std::string_view what);
50 static
void to_json(
std::ostream& os,
int code, const
char* message);
56 static
void to_json(
std::ostream& os, const
std::error_code& code, const
char* message)
58 to_json(os, code.value(), message);
66 const std::error_code&
code() const noexcept {
return ec_; }
74template <
typename ExceptionT>
79template <
typename ExceptionT>
86template <
typename ExceptionT>
91template <
typename ExceptionT>
94 return os <<
val.e->what() <<
" (" <<
val.e->code().value() <<
')';
99template <
typename ExceptionT>
102 return detail::PutAsJson<ExceptionT>{.e = &e};
105template <
typename ExceptionT>
108 return detail::PutWithCode<ExceptionT>{.e = &e};