HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)
4- 90
statement.
100 ON ERROR GOTO 115
105 A=B/0 !Error occurs; go to line 115
115 PRINT "ERROR"
116 CALL Sub1
120 END
130 SUB Sub1 !ON ERROR at line 100 inactive within Sub1
140 I=J/0 !Error aborts program
150 SUBEND
100 ON ERROR GOSUB 115
105 A=B/0 !Error occurs; gosub line 115.
110 CALL Sub1
115 PRINT "ERROR"
116 RETURN !Return to line 110.
120 END
130 SUB Sub1 !ON ERROR at line 100 inactive in Sub1
140 I=J/0 !Error aborts program.
150 SUBEND
100 ON ERROR CALL Error
110 A=B/0 !Error occurs; call Error; return will be to
115 !line 115
120 CALL Sub1
130 END
141 SUB Error
150 PRINT "ERROR"
160 SUBEND
170 SUB Sub1 !ON ERROR still active within Sub1
180 I=J/0 !Error occurs; call Error
190 SUBEND
The next example shows how a local ON ERROR statement overrides an active
ON ERROR statement in the calling program unit.
100 ON ERROR CALL Error
105 P=Q/0 !Error occurs; call Error
110 CALL Sub1
115 R=S/0 !Error occurs; call Error
120 CALL Sub2
125 T=U/0 !Error occurs; call Error
130 END
140 SUB Sub1
150 A=B/0 !Error occurs; call Error
160 SUBEND
170 SUB Sub2
175 M=N/0 !Error occurs; call Error
180 ON ERROR GOSUB 240 !Overrides line 100
190 I=J/0 !Error occurs; GOSUB 210
200 GOTO 230
210 PRINT "Error at line 190"
220 RETURN
230 SUBEND
240 SUB Error
250 PRINT "Error at line 105,115,125,150, or 175"
260 SUBEND
ON GOSUB
The ON GOSUB statement is one of the GOSUB corollaries of the ON GOTO and
GOTO OF statements. Control is transferred to the selected line, L, by
"GOSUB L" rather than "GOTO L." A RETURN statement returns control to the
statement that follows the ON GOSUB statement. Although the ON GOSUB
statement can be input as ON GOSUB or ON GO SUB, HP Business BASIC/XL
will always list it as ON GOSUB.