| `PARSE ERROR` | The line could not be turned into a statement. Nothing on it ran. Also what the four prescans report as, since they run before any statement does. |
| 512 | `Syntax Error` | A line that will not parse, a verb given the wrong shape of arguments, a keyword where a value belongs, or a branch by number to a line the program did not number. The commonest code and the only one that can arrive before a statement runs. |
| 513 | `Type Error` | A string where a number belongs or the reverse — `LEFT(1, 2)`, `A$ = 1 + "X"` used as a number, a non-integer array subscript. |
| 514 | `Undefined Reference` | A branch to a label that does not exist, or a call to a function that was never defined. A branch to a *line* that does not exist raises nothing at all: `GOTO 500` with no line 500 walks to the end of the program and stops, which is the same answer `RENUMBER` gives such a branch. |
| 515 | `Out Of Bounds` | An array subscript past the end, a colour index outside 1 to 16, a sprite number outside 1 to 8, a `RGR` or `RSPRITE` field number that is not a field. |
| 516 | `Environment Error` | The scope pool is exhausted — 32 nested `GOSUB`, `FOR` or `DEF` bodies. **See below: this is the one code you cannot usefully trap.** |
| 517 | `Value Error` | A number that is the wrong number: division by zero, a negative `SCALE` maximum, a string longer than 255 characters, a `GSHAPE` handed a string that did not come from `SSHAPE`. |
| 518 | `State Error` | A verb run outside the structure it needs — `RESUME` with no handler running, `NEXT` with no `FOR`, `LOOP` with no `DO`. |
| 519 | `Device Error` | A verb needs a graphics, audio, input or sprite device the runtime has not been given, or one that cannot do what was asked. Everything in Chapters 6, 7 and 8 refuses with this in a build with no window. `FILTER` and `SYS` refuse with it always. |
**516 is not usefully trappable and that is inherent, not a defect.** Entering a
handler takes a scope, and the pool being empty is exactly what raised the error — so
a program that exhausts it gets the report rather than the handler. Runaway recursion
is the way to reach it, and a handler that could not run is the right answer to it.
## Codes from underneath
`ER#` carries whatever code the failure was raised with, and not every failure comes
from the interpreter. Two other kinds reach a program.
**Errors from the C library, as `errno`.** The disk verbs open, read and delete real
files, and a real file refuses for the reasons files refuse:
```basic
10 TRAP 100
20 DOPEN 1, "nosuchfile.bas"
30 END
100 PRINT "" + ER# + " " + ERR(ER#)
110 END
```
```output
2 No such file or directory
```
2 is `ENOENT`. Any `errno` your platform defines can arrive this way, with the text
your C library gives it — so this is the one part of the table that is your machine's
rather than this document's.
**Errors from the libraries akbasic is built on.** `libakerror` names its own codes
just above the `errno` range, and they surface when something fails below the language
rather than in it — `SCRATCH` on a file that will not delete gives its
`Input Output Error`, and `VAL` of text that is not a number gives its `Value Error`
rather than the interpreter's 517, because the conversion happens in `libakstdlib` and
the code comes back up with it. In the SDL build, `libakgl` owns 256 to 260 and an
`SDL Error` can reach `ER#` if the renderer itself refuses.
**Do not hardcode those numbers.** `libakerror`'s codes are defined as offsets from
the largest `errno` your platform has, so the same code is a different integer on a
different machine — on the machine this was written on the range begins at 134, and
that is not a promise. The interpreter's own 512 to 519 are absolute and are the only
numbers worth writing into a program.
## Two codes render as the same text
`ERR()` gives the *registered name* for a code, and two pairs of them collide:
| Text | Given by |
|---|---|
| `Type Error` | 513, and `libakerror`'s own type error |
| `Value Error` | 517, and `libakerror`'s own value error |
The `Value Error` pair is not hypothetical — it is the `VAL` case above:
```basic
10 TRAP 100
20 PRINT VAL("XYZ")
30 END
100 PRINT ERR(ER#)
110 IF ER# = 517 THEN PRINT "INTERPRETER"
120 IF ER# <> 517 THEN PRINT "FROM UNDERNEATH"
130 END
```
```output
Value Error
FROM UNDERNEATH
```
So `IF ERR(ER#) = "Value Error" THEN` is not a reliable test and `IF ER# = 517 THEN`
is. **Compare the code; print the text.**
## What is not in `ER#`
An error the interpreter reports *about the host* rather than about your program never
reaches `ER#`, because it is not the program's error to catch — a font that will not
open, a window that will not create. Those come out of the embedding API instead;
Chapter 14 draws that line, and Chapter 10 is what a host does with it.