Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making the output print errors?

Asked by 10 years ago

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?

3 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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).

0
Thanks! this is the exact function I was looking for, I couldn't recall it at first but I knew something existed like this. :) IntellectualBeing 430 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

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?

Log in to vote
-3
Answered by 10 years ago

For my sakes.

print("Hello")

Answer this question