-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathException.gml
More file actions
61 lines (48 loc) · 2.06 KB
/
Copy pathException.gml
File metadata and controls
61 lines (48 loc) · 2.06 KB
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
globalvar __YYGMLException_static;
// catch a system runtime exception to get its static struct
try {
show_error("test", false);
} catch(exception) {
__YYGMLException_static = static_get(exception);
}
/// @ignore
/// @description Base class for exceptions
function Exception() constructor {
static_set(self, __YYGMLException_static); // inherit from system YYGMLException
message = "";
longMessage = "";
script = "";
line = -1;
stacktrace = []; /// @is {string[]}
// TODO: Check callstack format on different target platfroms
// TODO: Replace string functions with buffer mutations?
var stack = debug_get_callstack();
for (var i = 2, length = array_length(stack) - 1; i < length; i++) {
var stackline = stack[i];
var colonPos = string_pos(":", stackline);
if (i == 2) {
script = string_copy(stackline, 1, colonPos - 1);
line = real(string_copy(stackline, colonPos + 1, string_length(stackline) - colonPos));
}
stackline = string_replace(stackline, ":", " (line ");
stackline += ")";
array_push(stacktrace, stackline);
}
static toString = function() {
return longMessage;
}
static init = function() {
var exceptionName/*:string*/ = /*#cast*/ instanceof(self);
message = string("{0}: {1}", exceptionName, message);
longMessage = string("{0}\r\n{1}", exceptionName, longMessage);
// add more info for YYC as it is not adding standard error output like on VM
if (code_is_compiled()) {
longMessage = string("Unable to find a handler for exception {0}\r\n", longMessage);
for (var i = 0, length = array_length(stacktrace); i < length; i++) {
longMessage += "\r\n" + stacktrace[i];
}
}
// fixes for weird constructor inheritance GM bug and YYC shenanigans
static_set(self, static_get(Exception));
}
}