diff --git a/source/mijin/util/exception.hpp b/source/mijin/util/exception.hpp index b27f1f5..2074f84 100644 --- a/source/mijin/util/exception.hpp +++ b/source/mijin/util/exception.hpp @@ -6,6 +6,8 @@ #include +#include "../debug/stacktrace.hpp" + namespace mijin { @@ -13,6 +15,26 @@ namespace mijin // public defines // +// +// public types +// + +class Exception : public std::runtime_error +{ +private: + Result stacktrace_; + std::exception_ptr cause_; +public: + Exception(const std::string& what) : std::runtime_error(what), stacktrace_(captureStacktrace(1)), cause_(std::current_exception()) {} + Exception(const char* what) : Exception(std::string(what)) {} + + [[nodiscard]] + const Result& getStacktrace() const noexcept { return stacktrace_; } + + [[nodiscard]] + const std::exception_ptr& getCause() const noexcept { return cause_; } +}; + // // public functions //