Add stacktrace to runtime errors

This commit is contained in:
ala89 2024-01-03 18:59:34 +01:00
parent 0ffb2b4884
commit 2d8316d7ff
2 changed files with 7 additions and 8 deletions

View File

@ -56,6 +56,8 @@ enum class ErrorType {
using ErrorData = variant<monostate, string, int>;
using StackTrace = vector<tuple<string, CodePosition>>;
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<string> history, CodePosition pos);
/**
* Returns the error message associated with a user error
*/
string get_error_message(const UserError& e);
#endif

View File

@ -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;
}