I have always wanted to know how to print out an error if something goes wrong and have it print exactly went wrong, I heard there is a way to use like an error service or something, I'm pretty much in the dust for all I know. Can anyone clarify?
I know how to print something in the output.
print('Hello')
But is it just simply doing that or is it something more advanced?
For simple usage, you can just use the error
function!
The error function on the Wiki
This, however, will stop any code that is not in a protected call so you usually shouldn't use it except to debug!
The TestService allows you to print Warnings (the Warn
method) and errors (Error
).
You can use the TestService as a instance to print errors and warnings, just using the "error" function as BlueTaslem said! By the way, I want a faster and simpler method like java's try/catch one and converted to lua, like this:
// Java code public void printHello() { try { System.out.println("Hello"); } catch (Exception e) { System.err.println("The function cannot be called!"); e.printStackTrace(); } } -- Lua code function printHello() try print("Hello"); catch print("The function cannot be called!"); error(); end end
Isn't it better?