This is a base class for custom exceptions. It replicates a structure of system exceptions and adding better support of try-catch and exception_unhandled_handler for these custom exceptions.
The class is generating all the necessary exception fields and populates data for script
, line
and stacktrace
ones. Makes output on error windows nicer and more meaningful on handled exceptions. Also adds better support for YYC.
To create a custom exception inherit your constructor from Exception
, write your message
and longMessage
and add init()
call:
function TestException() : Exception() constructor {
message = "Throw a test exception.";
longMessage = "Long\nMessage\nis\nhere";
init();
}
You can also not set both messages, which will make it hold just the exception class name, or make messages the same. Arguments are also supported:
function ArgumentException(expected_number, given_number) : Exception() constructor {
message = string("Number of arguments expected {0}, got {1}", expected_number, given_number);
longMessage = message;
init();
}
Copy the Exception script into your project.
Or get the latest asset package from the releases page and import it into IDE.
In GameMaker there are differences in error message appearance and exception data between different handling methods (try-catch or exception_unhandled_handler) and compile targets (VM or YYC).
This implementation tries to produce generally better and more consistent results in comparison to its alternatives.
VM | YYC | |
---|---|---|
Unhandled | ||
try-catch | "ArgumentException" | "ArgumentException" |
exception |
] |
"ArgumentException" |
VM | YYC | |
---|---|---|
Unhandled | ||
try-catch |
] |
] |
exception |
] |
] |
Nikita Musatov - MusNik / KeeVee Games
License: MIT