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:
Line 4, Column 1
3 | fn main() -> Int
4 | {
^
InvalidBlock: Expected a block
----------
Line 6, Column 5
5 | total: Float = 3.4
6 | a: [Int] = [1, 3, -4, 2, 0, 6, -6];
^
MissingExpression: Expected ';' but got 'a'.
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.
fn main() -> Int
{
// Returns a String when the function should return an Int
return ("Program won't compile.");
}
When compiled, this code generates the following error messages:
> glados build ./source.gom
Type mismatch, found 'AGomTypeList [AGomType "Char"]' but expected 'AGomType "Int"'."
Last updated
Was this helpful?