English
Language : 

NSB8 Datasheet, PDF (118/158 Pages) List of Unclassifed Manufacturers – BASIC interpreter for Z80 family
grifo®
ITALIAN TECHNOLOGY
ERROR TRAPPING AND RECOVERY
Normally, when a program error occurs while a BASIC program is running, BASIC automatically
terminates the execution of the program and issues an error message. This is to aid the programmer
in finding and correcting the error. For many possible end user applications, a BASIC program
should operate in the presence of errors rather than terminate execution and print an error
message. The program should detect the error condition, and then take corrective action without
requiring the user to debug and rexecute the program. Certain kinds of errors resulting from incorrect
input, improper diskette handling, or inconsistent data might be too difficult or time consuming to
anticipate and detect using regular BASIC statements.
To make convenient error recovery under program control possible, NSB8 includes the special
ERRSET statement. With this statement, the programmer specifies a line number which references
the first statement of an error recovery routine, which exists somewhere in the program. Once an
ERRSET has specified the desired error recovery routine, any program error which occurs during
program execution will cause an immediate execution of that routine (this is called trapping the
error). The BASIC statements in the error recovery routine determine the action to take under error
conditions. A good routine will also include statements which attempt to correct the error condition. For
example, if a user was told to insert a diskette into a drive, and then the computer detects a hard disk
error when it attempts to open a file on the diskette, either the diskette has been inserted incorrectly,
or the data on it is invalid. A good error recovery routine might give the user a chance to reinsert the
diskette.
The programmer must also specify two variable names in the ERRSET statement along with the line
number of the start of the error recovery routine, for example:
10 ERRSET 1000,L,E
When an error is trapped, the line number of the statement where the error occurred is assigned as
the value of the first variable, and a numeric code, corresponding to the type of the error, is assigned
to the second variable. By examining the value of these two variables, the program can determine
not only what caused the error condition, but where in the program it occurred, and with this
knowledge, decide what to do about the error. NSB8 program errors and their codes are listed in
appendix B.
Note that if the error handling routine in a program is written to make any decisions based on the
number of the line in which the error occurs, it may be very unwise to renumber the program.
When an error trap occurs, any subroutines, user functions, and FOR NEXT loops which were active
at the trap time are still active. Thus, it is possible to execute a GOTO statement back to the point
where the error occurred, or to the statement immediately after that point, and continue the execution
of the program after the error condition has been handled.
Error trapping is disabled automatically after each trap. After error recovery is complete, another
ERRSET statement can be executed to resume error trapping mode.
When the program no longer requires the use of BASIC’s error trapping feature, error trapping can
be disabled explicitly by executing the ERRSET statement with no arguments, for example:
100 ERRSET
Unless the <control-C> program interruption feature is disabled (as mentioned in section
CONTROL-C, and section PERSONALIZING BASIC) a trappable program error will occur every
time <control-C> is pressed while the program is running in error trapping mode. If you do not wish
Page 106
NSB8
Rel. 5.10