Exceptions - markpwns1/Dormez GitHub Wiki
Exceptions in Dormez are simple. Any error will create an exception, even syntax errors. At the moment, there are no different kinds of exceptions. Exceptions can be caught with a try-catch block.
try {
asdf // will throw an error
} catch {
console.print("Something went wrong!");
}
You may also capture the message, line, and column of the exception.
try {
asdf
} catch : exception, line, column {
console.print("Error!\n'" + exception.toString() + "' on line " + line + ", column " + column);
}
This will print the following:
Error!
'Variable does not exist in this scope: asdf' on line 29, column 4
You can also throw your own exceptions with the throw
keyword. For example:
try {
throw "THIS CODE HAS BEEN SABOTAGED";
} catch {
throw "NOT EVEN A TRY-CATCH BLOCK CAN SAVE YOU NOW";
}
And it will show in console:
FATAL ERROR @ ln xx, col xx: NOT EVEN A TRY-CATCH BLOCK CAN SAVE YOU NOW