ON ERROR

A statement controlling error trapping. If an ON ERROR statement has been encountered, BBC BASIC (Z80) will transfer control to it (without taking any reporting action) when an error is detected. This allows error reporting/recovery to be controlled by the program. However, the program control stack is still cleared when the error is detected and it is not possible to RETURN to the point where the error occurred.

ON ERROR OFF returns the control of error handling to BBC BASIC (Z80).

ON ERROR PRINT"Suicide":END
ON ERROR GOTO 100
ON ERROR OFF

For example, the ON ERROR statement can be used to trap out the Escape key to prevent a program being terminated at the wrong time by its accidental use.

50 ON ERROR IF ERR=17 THEN 70
60 PRINT:REPORT:PRINT " at line ";ERL:END
70 ...

Error Handling is explained more fully in the overview section.

Syntax

Associated Keywords