Added exception type that automatically captures stacktrace and "parent" exception when constructed.

This commit is contained in:
Patrick 2024-10-12 22:34:10 +02:00
parent 4735fc10f8
commit 77d46d986c

View File

@ -6,6 +6,8 @@
#include <stdexcept>
#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> 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<Stacktrace>& getStacktrace() const noexcept { return stacktrace_; }
[[nodiscard]]
const std::exception_ptr& getCause() const noexcept { return cause_; }
};
//
// public functions
//