Error handling

Syntax Error

In GoMelan, if your code contains syntax errors such as missing semicolons ; or curly braces {, the compiler will display an error message in your terminal, pinpointing the exact location and nature of the issue. For example:

Consider the following GoMelan code:

fn power(x: Int, y: Int) -> Int;

fn main() -> Int
{
    total: Float = 3.4
    a: [Int] = [1, 3, -4, 2, 0, 6, -6];

    return power(floatToInt(total) + sum(a), 3);
}

fn power(x: Int, y: Int) -> Int
{
    if (x == 0) {
         return 0;
    }
    if (y < 0) {
        return (power(x, y – 1) / x);
    }
    return (power(x, y – 1) * x);
}

When compiled, this code generates the following error messages:

Type Mismatch Error

GoMelan is a strongly typed language. If the compiler happens to find a type different to its expected use case, the compilation will be canceled.

When compiled, this code generates the following error messages:

Last updated

Was this helpful?