HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)
4-: 89
Table 4-8. ON ERROR STATEMENTS
---------------------------------------------------------------------------------------------
||||
| Statement Selected | Line to Which | Scope of ON ERROR |
||Control is Transferred | Statement |
||following ON ERROR ||
||processing ||
||||
---------------------------------------------------------------------------------------------
||||
| GOTO
line_id
| None. | Program unit that contains |
| | | it. |
||||
---------------------------------------------------------------------------------------------
||||
| GOSUB
line_id
| Line following the line | Program unit that contains |
| | where the error occurred. | it. |
||||
---------------------------------------------------------------------------------------------
||||
| CALL
sub_id
| Line following the line | Program unit that contains |
| | where the error occurred. | it and program unit that it |
| | | calls, until called unit |
| | | executes a local ON ERROR |
| | | statement or an OFF ERROR |
| | | statement. |
||||
---------------------------------------------------------------------------------------------
HP Business BASIC/XL provides predefined functions that can be used in
error recovery routines. They are ERRL, ERRN, ERRM$, and ERRMSHORT$.
They are defined in chapter 5.
Examples
100 ON ERROR CALL Default
110 READ A,B
120 C=B/A !Error can occur here
130 DISP A,B,C
135 END
140 SUB Default
150 C=0
160 SUBEND
The next three examples show how the three forms of the ON ERROR
statement transfer control when errors occur.
100 ON ERROR GOTO 140
110 I=J/0 !Error occurs; go to line 140.
120 PRINT "DONE" !This statement is never executed.
130 GOTO 999
140 PRINT "ERROR" !Execute line 999 next.
999 END
100 ON ERROR GOSUB 140
110 I=J/0 !Error occurs; gosub line 140.
120 PRINT "DONE"
130 GOTO 999
140 PRINT "ERROR"
150 RETURN !Return to line 120.
999 END
100 ON ERROR CALL Error
110 I=J/0 !Error occurs; call to line 140.
120 PRINT "DONE"
130 END
135 SUB Error
140 PRINT "ERROR"
150 SUBEND !Return to line 120.
The next three examples show the scope of the three forms of the ON ERROR