Added exception type that automatically captures stacktrace and "parent" exception when constructed.
This commit is contained in:
parent
4735fc10f8
commit
77d46d986c
@ -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
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user