17#ifndef TOOLBOX_UTIL_EXCEPTION_HPP
18#define TOOLBOX_UTIL_EXCEPTION_HPP
26inline namespace util {
36template <
typename ValueT>
45 explicit Exception(std::error_code ec = std::error_code());
46 Exception(
int err,
const std::error_category& ecat);
47 Exception(std::error_code ec, std::string_view what);
48 Exception(
int err,
const std::error_category& ecat, std::string_view what);
63 static
void to_json(
std::ostream& os,
int code, const
char* message);
69 static
void to_json(
std::ostream& os, const
std::error_code& code, const
char* message)
71 to_json(os, code.value(), message);
79 const std::error_code&
code() const noexcept {
return ec_; }
87template <
typename ExceptionT>
92template <
typename ExceptionT,
typename StreamT>
100template <
typename ExceptionT>
105template <
typename ExceptionT,
typename StreamT>
109 os <<
val.e->what() <<
" (" <<
val.e->code().value() <<
')';
115template <
typename ExceptionT>
118 return detail::PutAsJson<ExceptionT>{.e = &e};
121template <
typename ExceptionT>
124 return detail::PutWithCode<ExceptionT>{.e = &e};
ostream & operator<<(ostream &os, const pair< T, U > &p)