31 #ifndef LEDGER_CORE_EXCEPTION_HPP 32 #define LEDGER_CORE_EXCEPTION_HPP 36 #include "../api/ErrorCode.hpp" 37 #include "../api/Error.hpp" 38 #include "../utils/Option.hpp" 40 #include <fmt/format.h> 48 Option<std::shared_ptr<void>> userData =
Option<std::shared_ptr<void>>());
50 std::string getMessage()
const;
54 return _userData.map<std::shared_ptr<T>>([] (
const std::shared_ptr<void>& ptr) -> std::shared_ptr<T> {
55 return std::static_pointer_cast<T>(ptr);
63 virtual const char *what()
const noexcept
override;
65 friend std::ostream &operator<<(std::ostream &os,
const Exception &e) {
66 return os <<
"Exception(" << e.getMessage() <<
")";
78 template <
typename... Args>
80 return Exception(code, fmt::format(format, args...));
83 template <
typename... Args>
84 Exception make_exception(
api::ErrorCode code, std::shared_ptr<void> userData,
const std::string& format,
const Args&... args) {
85 return Exception(code, fmt::format(format, args...), userData);
91 #endif //LEDGER_CORE_EXCEPTION_HPP Definition: Option.hpp:49
Definition: Account.cpp:8
ErrorCode
Definition: ErrorCode.hpp:20
Definition: optional.hpp:177
Definition: Exception.hpp:45