Added exception type that automatically captures stacktrace and "parent" exception when constructed.
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "../debug/stacktrace.hpp"
|
||||||
|
|
||||||
namespace mijin
|
namespace mijin
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -13,6 +15,26 @@ namespace mijin
|
|||||||
// public defines
|
// 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
|
// public functions
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user