On err goto – Remote Processing CAMBASIC User Manual

Page 119

Advertising
background image

Comm ands - 86

ON ERR GOTO

Statement

SYNTAX:

ON ERR GOTO line/label

PURPOSE:

To enable error trapping and specify the first line of the error handling subroutine.

REMARK S:

Once err or trapping has be en enabled, all error s detected by CA MBASIC during run tim e cause
CAM BASIC to branch to the specified line.

To disable error trapping, execute an ON ERR without the line number. If the routine beginning at
line has an error, an infinite loop will be set up. In this case, do a hardw are reset and execute the
UNNEW ! command. The error trapping subroutine should be tested before executing an ON ERR
statemen t.

The O N ER R GO TO line s tatement m ust be per form ed ever y time an er ror o ccurs if yo u wish to
continue to trap on errors. The best place to do this is in the error handling routine.

RELATED:

RESUME, RESUME NEXT

EXAMPLE:

10 ON ERR GOTO 100
20 A=5/0
30 END
100 PRINT "DIV BY ZERO"
110 ON ERR GOTO 100
120 RESUME NEXT

In this case just using RESUM E without the NEXT would cause line 20 to be executed again,
producing another error.

10 ON ERR GOTO

: 'disable error trapping

ERROR:

< Can’t compile> – if line/label does not exist

Advertising