From 2d8316d7ffe45ef813e3448facda22e770ff8c49 Mon Sep 17 00:00:00 2001 From: ala89 Date: Wed, 3 Jan 2024 18:59:34 +0100 Subject: [PATCH] Add stacktrace to runtime errors --- src/include/errors.h | 11 +++++------ src/main.cpp | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/include/errors.h b/src/include/errors.h index 6ca051a..4135836 100644 --- a/src/include/errors.h +++ b/src/include/errors.h @@ -56,6 +56,8 @@ enum class ErrorType { using ErrorData = variant; +using StackTrace = vector>; + class UserError : public exception { public: explicit UserError(ErrorType type, CodePosition pos, ErrorData data = {}) @@ -93,7 +95,9 @@ public: class RuntimeError : public UserError { public: explicit RuntimeError(ErrorType type, CodePosition pos, ErrorData data = {}) - : UserError(type, pos, data) {} + : UserError(type, pos, data), trace() {} + + const StackTrace trace; }; class InternalError : public exception { @@ -113,9 +117,4 @@ public: */ void print_error_position(vector history, CodePosition pos); -/** - * Returns the error message associated with a user error -*/ -string get_error_message(const UserError& e); - #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8355dad..a71ed6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -119,8 +119,8 @@ int main(int argc, char* argv[]) { cout << BOLD RED "Type Error: " RESET << e.get_message() << endl; } catch (const RuntimeError& e) { - print_error_position(input, e.pos); - cout << BOLD RED "Runtime Error: " RESET << e.get_message() << endl; + // print_error_position(input, e.pos); + // cout << BOLD RED "Runtime Error: " RESET << e.get_message() << endl; } cout << endl; }