Error Handling

Vortex allows you to safe-guard against errors using try/catch.

const add = (a, b) => {
    try {
        return a + b
    } catch (e) {
        println(e)
        return (-1)
    }
}

add(5, 10).println() // 15

add(5, "a").println()

/*
{ message: Cannot perform operation '+' on values: 5 (Number), a (String), type: GenericError, line: 52, path: src/main.vtx }
-1
*/

Hitting the catch block exposes the error object, and you can handle it in any way you choose.

To throw an error, simply return an Error() call:

Output:

Note that when an error is not handled, the program will exit and print the stack trace to the console. Here is an example of a deeply nested error:

Last updated