
Chapter 9. Event Polling and Error/Event Trapping
131
9.3 Error Trapping
[ 1 ] Overview
If a run-time error occurs during program running, error trapping makes the program cause an
interrupt upon completion of the machine instruction so as to transfer control from the current
program to the error-handling routine which has been specified by a label.
If a run-time error occurs when this trapping ability is disabled, the Interpreter will terminate
the current user program while displaying the error message as shown below.
Error message sample:
ERL=38A4 ERR=0034
The above message indicates that a run-time error has occurred at address 38A4h and its
error code is 34h. Both the address and error code are expressed in hexadecimal notation.
The address is a relative address and corresponds to the address in the program list
outputted by the Compiler. According to this address indication, you can pinpoint the program
line where the run-time error has occurred.
The error code 34h (52 in decimal notation) means that the user program attempted to access
a file not opened. (Refer to Appendix A1, "Run-time Errors.")
The ERL and ERR functions described in an error-handling routine will return the same values,
38A4h and 34h, respectively.
NOTE
If an error occurs during execution of user-defined functions or subroutines so
that the error is trapped and handled by the error-handling routine, then do not
directly pass control back to the main routine having the different stack level by
using the RESUME statement. The return address from the user-defined
functions or subroutines will be left on the stack, causing a run-time error due to
stack overflow.
To prevent such a problem, once transfer control to the routine which caused the
interrupt in order to match the stack level and then jump to any other desired
routine.
(Refer to Chapter 3, Section 3.1, "Program Overview.")
Kommentare zu diesen Handbüchern