# 3.15 Checking levels

> The engine checks everything it can before running; whatever depends on concrete values, such as dividing by zero, it checks when running.

Web page: https://pseudolearn.app/en/spec/tipos/niveles

> **In one sentence**
>
> The engine checks everything it can before running; whatever depends on concrete values, such as dividing by zero, it checks when running.

## 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.

**Figure 3.15-1: Before and during the run**

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.

What is checked at each moment. The earlier an error is found, the cheaper it is to fix.

This program is correct for the analysis, because dividing two integers makes sense. But when running, the divisor is zero:

### Program: Correct when analysed, fails when run

```pseudolearn
Algorithm DividirCero
  Define edad As Integer <- 10;
  Define divisor As Integer <- 0;
  Write edad Div divisor;
EndAlgorithm
```

**Diagnostics**
- `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:

### Program: An error seen beforehand

```pseudolearn
Algorithm TipoMal
  Define edad As Integer <- "diez";
EndAlgorithm
```

**Diagnostics**
- `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`.

**See also**
- [1.6 Errors, warnings and failures](https://pseudolearn.app/en/spec/vision/errores.md)
- [13.4 Effect order and the tape](https://pseudolearn.app/en/spec/motor/efectos.md)
