Compile-Time Errors and Runtime Errors

Errors may occur during program loading (so called compile-time errors) or during program execution (so called runtime errors). Fortunately, most errors are detected at compile-time. This detection includes missing files, syntax errors, type errors and unexpected identifiers. The developer gets feedback immediately when he tries to load the program. Thus, a part of unexpected failures during machining is avoided.

However, there are also errors that, by their nature, cannot be detected at compile-time. For instance, this circumstance includes a division by zero, since the divisor may be computed dynamically. If a runtime error occurs, the interpreter is stopped safely and an error message is produced. A runtime error message is similar to a compile-time error message. It even includes a reference to the pertinent source code.

Example:

In the following example the FOR-loop contains a division of 10 by the loop variable i. Since the variable i is iterated from -3 to 3, this program leads to an error during the 4th iteration, when i has the value 0. This error is detected at runtime and stops the interpreter. The error message shown below is reported. It points precisely to the code ‘10/i’ in the example.

FILE aaa.nc:

{
VAR
    i, j : int;
END_VAR

FOR i := -3 TO 3 DO
    j := j + 10/i;
END_FOR;
}
M02

Error message:

aaa.nc: 7.12-7.16: Division by zero

Example:

At runtime the interpreter also performs checking of array bounds. Consequently, invalid indices do not result in unpredictable and typically fatal crashes. The runtime error message precisely defines location and origin of the error at ‘idx’, reports the erroneously supplied index (20) and the valid index range (10..19).

FILE aaa.nc:

{
VAR
    idx : INT;
    a : ARRAY [10..19] OF INT;
END_VAR

FOR idx := 10 TO 20 DO
    a[idx] := i;
END_FOR;
}
M02

Error message:

aaa.nc: 8.5-8.8: Out of bounds. 20 exceeds range 10..19.