3.15.1 How it works
There are two moments to discover a problem:
- Before running (static checking): the shape of the program, that names exist and that types fit. If something fails here, the program does not run.
- When running (dynamic checking): whatever depends on the real value at that moment, such as dividing by zero, going outside an array or reading a variable without a value.
Two columns. Before running, shape, names, types and called subroutines are checked. When running, division by zero, indices, variables without a value and overflow are checked.
This program is correct for the analysis, because dividing two integers makes sense. But when running, the divisor is zero:
ProgramCorrect when analysed, fails when run
Algorithm DividirCero
Define edad As Integer <- 10;
Define divisor As Integer <- 0;
Write edad Div divisor;
EndAlgorithmDiagnostics
divisionByZero· error · 4:14 · Division by zero
The program finishes with an error.
On the other hand, storing a text in an integer variable is found without running anything:
ProgramAn error seen beforehand
Algorithm TipoMal
Define edad As Integer <- "diez";
EndAlgorithmDiagnostics
incompatibleTypesInAssignment· error · 2:3 · Incompatible types in assignment: cannot assign string to integer
The program finishes with an error.
3.15.2 A failure is never silent
When a dynamic check fails, the program does not go on with an invented value: it stops at that statement with a diagnostic that says what happened and where. Expected failures from the outside world, such as a file that does not exist, do not stop the program: they come back as a Result so the program decides.
In short
- Before running, shape, names and types are checked.
- When running, concrete values are checked.
- A runtime failure stops the program with a precise diagnostic.
- Expected failures from outside arrive as a
Result.