error_create

error_create creates an error object.

e = error_create(domain, code, message)

Return Value

e is an error object.

Parameters

domain

domain is the group the error belongs to e.g. “file-error”.

code

code is the error number. The error number is only valid within a group.

message

message is the error message (string).

Comment

The 3 variables of the error object can be accessed using period (.) - the object member-selection expression e.g. e.message = "file not found";.

Example

def test()
{
    o = obj_create();
    e = o.load("d:/laksjdlksajd");
    if (type(e) == "error") {
        MessageBoxError("%s\n\nError-No.: %d\n%s", e.domain, e.code, e.message);
        return e;
    }
    return 0;
}

Use of error_create in a UniScript function:

def test(a, b)
{
    if (argsin() != 2) {
        return error_create("test-error", 1, "no of args must be 2");
    }
    return a+b;
}

The user of test() can use the return value to check if an error occurred:

res = test(1);
if (type(res) == "error") {
    MessageBox(res.message);
    ...
}
...

id-1376826