-
Notifications
You must be signed in to change notification settings - Fork 3
/
runtime_error.cpp
138 lines (104 loc) · 2.85 KB
/
runtime_error.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "runtime_error.h"
#include <iostream>
using namespace std;
jmp_buf vaiven::errorJmpBuf;
std::string vaiven::errMsg;
void vaiven::expectedInt() {
throwError(EXPECTED_INT);
}
void vaiven::expectedBool() {
throwError(EXPECTED_BOOL);
}
void vaiven::expectedDouble() {
throwError(EXPECTED_DOUBLE);
}
void vaiven::noSuchFunction() {
throwError(NO_SUCH_FUNCTION);
}
void vaiven::duplicateVar() {
throwError(DUPLICATE_VAR);
}
void vaiven::noSuchVar() {
throwError(NO_SUCH_VAR);
}
void vaiven::expectedStr() {
throwError(EXPECTED_STR);
}
void vaiven::expectedList() {
throwError(EXPECTED_LIST);
}
void vaiven::expectedObj() {
throwError(EXPECTED_OBJ);
}
void vaiven::expectedIntOrDouble() {
throwError(EXPECTED_INT_OR_DOUBLE);
}
void vaiven::expectedStrOrInt() {
throwError(EXPECTED_STR_OR_INT);
}
void vaiven::expectedStrOrIntOrDouble() {
throwError(EXPECTED_STR_OR_INT_OR_DOUBLE);
}
void vaiven::expectedListOrStr() {
throwError(EXPECTED_LIST_OR_STR);
}
void vaiven::expectedListOrObj() {
throwError(EXPECTED_LIST_OR_OBJ);
}
void vaiven::errString(std::string msg) {
vaiven::errMsg = msg;
throwError(USER_STR);
}
void vaiven::throwError(ErrorCode code) {
longjmp(errorJmpBuf, code);
}
void vaiven::defaultHandle(ErrorCode code) {
cout << "Error: ";
switch(code) {
case EXPECTED_INT:
cout << "Got a non-integer in an integer operation" << endl;
break;
case EXPECTED_BOOL:
cout << "Got a non-boolean in a boolean operation" << endl;
break;
case EXPECTED_DOUBLE:
cout << "Got a non-double in a double operation" << endl;
break;
case EXPECTED_STR:
cout << "Got a non-string in a string operation" << endl;
break;
case EXPECTED_LIST:
cout << "Got a non-list in a list operation" << endl;
break;
case EXPECTED_OBJ:
cout << "Got a non-object in an object operation" << endl;
break;
case EXPECTED_INT_OR_DOUBLE:
cout << "Got a wrong type in an operation for ints/doubles" << endl;
break;
case EXPECTED_STR_OR_INT:
cout << "Got a wrong type in an operation for ints/strings" << endl;
break;
case EXPECTED_STR_OR_INT_OR_DOUBLE:
cout << "Got a wrong type in an operation for ints/strings/doubles" << endl;
break;
case EXPECTED_LIST_OR_STR:
cout << "Got a wrong type in an operation for lists/strings" << endl;
break;
case EXPECTED_LIST_OR_OBJ:
cout << "Got a wrong type in an operation for objects/lists" << endl;
break;
case NO_SUCH_FUNCTION:
cout << "Called a function that does not exist" << endl;
break;
case DUPLICATE_VAR:
cout << "Duplicate variable" << endl;
break;
case NO_SUCH_VAR:
cout << "Accessed a var that does not exist" << endl;
break;
case USER_STR:
cout << vaiven::errMsg << endl;
break;
}
}