Commodore 128 Programmer's Reference Manual page 111

Hide thumbs Also See for 128:
Table of Contents

Advertisement

ONE STEP BEYOND SIMPLE BASIC
101
ERROR FUNCTIONS
Several reserved variables inherent in the system store information about program
H
errors. ER stores the error number. EL stores the relevant program line number.
! I
ERR$(N) returns the string representing ER or EL. In the example of division by zero,
ERR$(ER) returns "DIVISION BY ZERO" and ERR$(EL) returns "BREAK". Add
/—'
this to the program in the previous section. See Appendix A for a complete listing of
| !
errors.
DOS
ERRORS
j I
Information on disk errors is determined from the variables DS and DS$ where DS is the
!
error number (See Appendix B) and DS$ provides the error number, error message, and
track and sector of the error. DS$ reads the disk error channel and is used during a disk
f1
operation to determine why the disk drive error light is blinking.
I
Trying to read a directory without a disk in place results in the following error
when the PRINT DS$ command is issued:
74, DRIVE NOT READY, 00, 00
Appendix B highlights specific causes of errors. To convert a function key to read
the disk-drive error channel automatically, use:
KEY 1, "PRINT DS$ + CHR$(13)
TRACING AN ERROR
Some programs have many complex loops that are tedious to follow. A methodical
step-by-step trace is useful. The BASIC TRON and TROFF commands can be used
within a program as a debugging tool to trace specific routines.
Some errors can only be found by acting like the computer and methodically
following each instruction step-by-step, and then doing all the calculations until you
discover something wrong. Fortunately the Commodore 128 can trace errors for you.
Enter the direct command TRON prior to running a program. The program displays each
line number as they occur in brackets, followed by each result. (To slow down the
display, hold the Commodore (CO key down.)
Try it with this double loop:
10
FORA=1T05
20
FORB = 2T06
30
C = B*A:K = K + CPRINTK
40
NEXTB:NEXTA
50
PRINTK
The results will start off like this:
[10] [20] [30] [30] [30]2
[40] [30] [30] [30]5
meaning the first printed result is the number 2 after operations in lines 10, 20, 30 are
performed. Then lines 40 and 30 result in 5, etc. Notice three activities were performed
in line 30. The Trace function is turned off with the direct command TROFF.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents