ON ERROR is used to catch errors which would normally give a Basic Error message.
ON ERROR GOTO [line no]
ON ERROR GOTO 0
10 ON ERROR GOTO 1000 20 INPUT A 30 A = SQR(A) 40 PRINT A 50 GOTO 20 1000 A=ABS(A) 1010 PRINT "NEGATIVE NUMBER CORRECTED" 1020 RESUME 30
This example will trap negative numbers and correct the condition.
ON ERROR causes program execution to be diverted to an error handling subroutine.
Any error can be trapped. However, ON ERROR is normally used for correctable errors, e.g. magnitude errors, which could be caused by operator input etc.
An ON ERROR trap must be exited by either an RESUME statement or by ON ERROR GOTO 0 which will give the normal Basic error message.