Cleanup exception stacktraces, so the compile the same on Windows.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Stacktraces still appear to be empty on Windows, but that's an issue for a later day.
This commit is contained in:
@@ -9,12 +9,10 @@
|
||||
#include <source_location>
|
||||
#endif
|
||||
|
||||
#if !WINDOWS
|
||||
#if PRETTYTRACES
|
||||
#define BACKWARD_HAS_BFD 1
|
||||
#if PRETTYTRACES && !WINDOWS
|
||||
#define BACKWARD_HAS_DW 1
|
||||
#endif
|
||||
#include <backward.hpp>
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
namespace std {
|
||||
@@ -35,35 +33,24 @@ static constexpr const char* file_name(const char* path) {
|
||||
namespace ArbUt {
|
||||
/// @brief Implementation of std::logic_error that gives a stack trace when thrown.
|
||||
class Exception : std::logic_error {
|
||||
#if !WINDOWS
|
||||
backward::StackTrace _stack;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/// @brief Throw an exception with specified message.
|
||||
explicit Exception(const std::string& msg) : std::logic_error(msg) {
|
||||
#if !WINDOWS
|
||||
explicit Exception(const std::string& msg) : std::logic_error(msg), _stack({}) {
|
||||
_stack.load_here(32);
|
||||
#if DEBUG
|
||||
_stack.skip_n_firsts(2);
|
||||
#else
|
||||
_stack.skip_n_firsts(0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/// @brief Copy operator.
|
||||
Exception(const Exception& e) noexcept
|
||||
: std::logic_error(e.what())
|
||||
#if !WINDOWS
|
||||
,
|
||||
_stack(e._stack)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
Exception(const Exception& e) noexcept : std::logic_error(e.what()), _stack(e._stack) {}
|
||||
template <typename... Args>
|
||||
/// @brief Throw a nicely formatted exception. The exception message will have the file name, line number, message,
|
||||
/// along with any optional parameters passed.
|
||||
/// @brief Throw a nicely formatted exception. The exception message will have the file name, line number,
|
||||
/// message, along with any optional parameters passed.
|
||||
[[noreturn]] static void Throw(const std::string& expression, const std::source_location& location,
|
||||
const Args... args) {
|
||||
std::stringstream error;
|
||||
@@ -86,14 +73,9 @@ namespace ArbUt {
|
||||
/// retrieved.
|
||||
[[nodiscard]] std::string GetStacktrace([[maybe_unused]] size_t depth = 6,
|
||||
[[maybe_unused]] bool include_addr = true) const {
|
||||
#if !WINDOWS
|
||||
return BuildStacktraceFromStack(_stack, depth, include_addr);
|
||||
#else
|
||||
return "Stack trace not available on Windows.";
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !WINDOWS
|
||||
/// @brief Builds a string from a given stack.
|
||||
/// @param stack The stack to build the string from.
|
||||
/// @param depth The max number of stacks it should retrieve.
|
||||
@@ -170,7 +152,6 @@ namespace ArbUt {
|
||||
|
||||
ss << fileName << "[" << source.line << "] " << snippet << std::endl;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user