Error Handling
4-4
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.
10
ON ERROR GOTO
70
20
INPUT
A
30
B = A *
.3842
40
PRINT B
50
GOTO
20
70
IF
11
= ERR THEN PRINT
"Division
by
zero"
80
RESUME 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.
BASIC-SO