25 #ifndef CLOE_CORE_ERROR_HPP_ 26 #define CLOE_CORE_ERROR_HPP_ 35 class Error :
public std::exception {
37 explicit Error(
const std::string& what) : err_(what) {}
38 explicit Error(
const char* what) : err_(what) {}
40 template <
typename... Args>
41 explicit Error(
const char* format,
const Args&... args) : err_(fmt::format(format, args...)) {}
43 virtual ~Error() noexcept =
default;
45 const char* what()
const noexcept
override {
return err_.what(); }
47 bool has_explanation()
const {
return !explanation_.empty(); }
49 void set_explanation(
const std::string& explanation);
51 template <
typename... Args>
52 void set_explanation(
const char* format,
const Args&... args) {
53 set_explanation(fmt::format(format, args...));
56 const std::string& explanation()
const {
return explanation_; }
58 Error explanation(
const std::string& explanation) && {
59 set_explanation(explanation);
60 return std::move(*
this);
63 template <
typename... Args>
64 Error explanation(
const char* format,
const Args&... args) && {
65 set_explanation(fmt::format(format, args...));
66 return std::move(*
this);
70 std::runtime_error err_;
71 std::string explanation_;
85 std::exception& cause()
const noexcept {
return cause_; }
86 const char* what()
const noexcept
override {
return cause_.what(); }
89 std::exception& cause_;
94 #endif // CLOE_CORE_ERROR_HPP_
Definition: coordinator.hpp:36