# 1.6 Errors, warnings and failures

> The engine warns with diagnostics: errors prevent running, warnings do not, and failures happen while the program runs.

Web page: https://pseudolearn.app/en/spec/vision/errores

> **In one sentence**
>
> The engine warns with diagnostics: errors prevent running, warnings do not, and failures happen while the program runs.

## 1.6.1 How it works

Every notice from the engine is a **diagnostic**. They all have the same shape: a stable code, a severity, the exact position in the text and a message in the interface language. The code does not change with the language; that is why you can look it up in the catalogue.

Diagnostics are classified by **when** they are discovered:

| Class | When it appears | Example |
| --- | --- | --- |
| lexical | when the text is split into pieces | a character that does not exist in the language |
| syntax | when the pieces are grouped | a missing semicolon |
| semantic | when names and types are checked | a variable nobody defined |
| runtime | while the program runs | an index outside the array |

And by **severity**: an **error** prevents the program from running; a **warning** points out something suspicious but lets it run; an **information** only informs.

**Figure 1.6-1: Diagnostic classes**

Four stages in a column, lexical, syntax, semantic and runtime, each with an example on the right. A red bar next to the first three marks that they are discovered before running.

The diagnostic classes along the journey of the program. The first three are discovered before running.

A syntax error:

### Program: The semicolon is missing

```pseudolearn
Algorithm SinPunto
  Write "hola"
EndAlgorithm
```

**Diagnostics**
- `missingStatementTerminator` (error, 2:15): Expected a semicolon at the end of the statement

*The program finishes with an error.*

A semantic error:

### Program: A variable that does not exist

```pseudolearn
Algorithm SinDefinir
  Write total;
EndAlgorithm
```

**Diagnostics**
- `undeclaredVariable` (error, 2:9): Undeclared variable: total

*The program finishes with an error.*

A warning: the program runs anyway.

### Program: A variable too many

```pseudolearn
Algorithm SinUso
  Define usada As Integer <- 3;
  Define sobrante As Integer;
  Write usada;
EndAlgorithm
```

**Output**

```text
3
```

**Diagnostics**
- `variableDeclaredNeverUsed` (warning, 3:10): Variable declared but never used: sobrante

*The program finishes normally.*

A runtime failure: the analysis could not know that index 3 does not exist.

### Program: An index outside the array

```pseudolearn
Algorithm Fuera
  Dimension notas[3] As Integer;
  notas[0] <- 7;
  notas[1] <- 9;
  notas[2] <- 6;
  Write notas[3];
EndAlgorithm
```

**Diagnostics**
- `arrayIndexOutOfRange` (error, 6:9): Index 3 is out of range for an array of size 3

*The program finishes with an error.*

## 1.6.2 No cascades

If lexical or syntax analysis finds an error, the semantic checks do not run on the broken tree. That way a single slip does not multiply into dozens of messages that explain nothing.

**In short**
- A diagnostic has a code, a severity, a position and a translated message.
- Classes: lexical, syntax, semantic and runtime.
- Errors prevent running; warnings do not.
- Runtime failures depend on concrete values.

**See also**
- [10.1 Anatomy of a diagnostic](https://pseudolearn.app/en/spec/diagnosticos/anatomia.md)
- [C.1 Diagnostic catalogue](https://pseudolearn.app/en/spec/apendice/diagnosticos.md)
- [1.5 How a program ends](https://pseudolearn.app/en/spec/vision/terminacion.md)
