Add stacktrace to runtime errors
This commit is contained in:
parent
0ffb2b4884
commit
2d8316d7ff
@ -56,6 +56,8 @@ enum class ErrorType {
|
|||||||
|
|
||||||
using ErrorData = variant<monostate, string, int>;
|
using ErrorData = variant<monostate, string, int>;
|
||||||
|
|
||||||
|
using StackTrace = vector<tuple<string, CodePosition>>;
|
||||||
|
|
||||||
class UserError : public exception {
|
class UserError : public exception {
|
||||||
public:
|
public:
|
||||||
explicit UserError(ErrorType type, CodePosition pos, ErrorData data = {})
|
explicit UserError(ErrorType type, CodePosition pos, ErrorData data = {})
|
||||||
@ -93,7 +95,9 @@ public:
|
|||||||
class RuntimeError : public UserError {
|
class RuntimeError : public UserError {
|
||||||
public:
|
public:
|
||||||
explicit RuntimeError(ErrorType type, CodePosition pos, ErrorData data = {})
|
explicit RuntimeError(ErrorType type, CodePosition pos, ErrorData data = {})
|
||||||
: UserError(type, pos, data) {}
|
: UserError(type, pos, data), trace() {}
|
||||||
|
|
||||||
|
const StackTrace trace;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InternalError : public exception {
|
class InternalError : public exception {
|
||||||
@ -113,9 +117,4 @@ public:
|
|||||||
*/
|
*/
|
||||||
void print_error_position(vector<string> history, CodePosition pos);
|
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
|
#endif
|
@ -119,8 +119,8 @@ int main(int argc, char* argv[]) {
|
|||||||
cout << BOLD RED "Type Error: " RESET << e.get_message() << endl;
|
cout << BOLD RED "Type Error: " RESET << e.get_message() << endl;
|
||||||
|
|
||||||
} catch (const RuntimeError& e) {
|
} catch (const RuntimeError& e) {
|
||||||
print_error_position(input, e.pos);
|
// print_error_position(input, e.pos);
|
||||||
cout << BOLD RED "Runtime Error: " RESET << e.get_message() << endl;
|
// cout << BOLD RED "Runtime Error: " RESET << e.get_message() << endl;
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user