17#ifndef TOOLBOX_UTIL_EXCEPTION_HPP
18#define TOOLBOX_UTIL_EXCEPTION_HPP
26inline namespace util {
38template <
typename ValueT>
47 explicit Exception(std::error_code ec = std::error_code());
48 Exception(
int err,
const std::error_category& ecat);
49 Exception(std::error_code ec, std::string_view what);
50 Exception(
int err,
const std::error_category& ecat, std::string_view what);
65 static
void to_json(
std::ostream& os,
int code, const
char* message);
71 static
void to_json(
std::ostream& os, const
std::error_code& code, const
char* message)
73 to_json(os, code.value(), message);
81 const std::error_code&
code() const noexcept {
return ec_; }
89template <
typename ExceptionT>
95template <
typename ExceptionT,
typename StreamT>
103template <
typename ExceptionT>
108template <
typename ExceptionT,
typename StreamT>
112 os <<
val.e->what() <<
" (" <<
val.e->code().value() <<
')';
118template <
typename ExceptionT>
121 return detail::PutAsJson<ExceptionT>{.e = &e};
124template <
typename ExceptionT>
127 return detail::PutWithCode<ExceptionT>{.e = &e};
ostream & operator<<(ostream &os, const pair< T, U > &p)