BASIC-80

Error Handling

10ON ERROR GOTO 100

20INPUT A

30PRINT 521 A

40GOTO 20

100PRINT "Error";ERR;"at line";ERL

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

120RESUME NEXT RUN

? 13 4

?0

Error 11 at line 30

Division by zero

?

Trace Facility

The TRON and TROFF (trace on and trace off) commands are used to examine the execution of each line. The line number of each program statement executed is displayed in brackets. The preceding example would run like this after entering TRON and then RUN:

[10][20]? • 5 (CR)

[30]10.4

[40][20]? • 7 (CR)

[30]7.428571

[40][20]? • 0 (CR)

[30][100] Error 11 at line 30

[110]Division by zero

[120][40] [20]? •

The ON ERROR OOTO 0 statement has a special meaning. When entered outside of error handling routines it disables any prior ON ERROR OOTO so that errors are handled normally-error messages are displayed and execution is lialted. When entered inside an error handling routine, it allows normal handling of a given error or errors, as shown in the example below.

10ON ERROR GOTO 100

20INPUT A,B

30PRINT AlB

40PRINT SQR(8-A}

50STOP

100IF ERR<>11 THEN 130

1108=1

120RESUME

130ON ERROR GOTO 0 RUN

? 2,0

2

Illegal function call in 40

Ok

The error routine (lines 100-130) sets B to 1 when the divide-by-zero error occurs, but allows other errors to interrupt operation in a conventional way.

The non-fatal floating-point overflow and divide-by-zero errors are trapped like other errors. No messages are displayed in this case, and the results of the calcula- tions are undefined.

4-3

Page 31
Image 31
Intel 9800758-02 manual Trace Facility