Error Handling

BASIC-SO

Error Simulation

BASIC-SO provides a statement that can simulate any errors which produce an error code. When the ERROR statement is encountered during program execution, BASIC-SO acts as if the specified error had occurred. The example below demonstrates how ERROR can be used to test an error handling routine.

10ON ERROR GOTO 70

20INPUT A

30B = A* .3842

40PRINT B

50GOTO 20

70IF 11 = ERR THEN PRINT "Division by zero"

80RESUME NEXT

If line 40 is replaced with:

40 ERROR 11

Program control transfers to line 70 regardless of the result of the operation in line 30.

Restarting Program Execution

You can restart program execution after it has halted with the RUN or CONT instruction, and after an error in an ON ERROR routine with the RESUME instruction. Remember that RUN sets all variables to zero.

RUN restarts program execution at the lowest-numbered line of a program if no line number is specified, or at the specified line number. It can be used at any time.

CONT restarts execution at the line after a STOP, END, or CONTROL-C is en- countered. CONT will also restart program execution after an error, but it will try to execute the erroneous line.

RESUME can only be used when the halt occurs in an ON ERROR routine. It is given following the error-resolving routine pointed to by the ON ERROR instruc- tion. It can be used three ways: RESUME to begin execution at the erroneous line; RESUME NEXT to begin execution at the line following the erroneous line; RESUME followed by a line number to begin execution at any other line.

4-4

Page 32
Image 32
Intel 9800758-02 manual Error Simulation, Restarting Program Execution, Error Handling, If line 40 is replaced with