The text of a manual · part 13 of 47
PDT 1100 Terminal Programmer's Guide: Chapter 2 Development Environment and Procedures, pages 107 to 110
Pages 107 to 110 of 413, from PDT 1100 Terminal Programmer's Guide
The original document is the PDF (3.5 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Symbol PDT-1100
Page 107
Event Polling and Error/Event Trapping
Error Trapping If an execution error occurs during a program, error trapping causes an interrupt upon completion of the machine instruction to transfer control from the current program to the error-handling routine specified by a label. If an execution error occurs when this trapping ability is disabled, the Interpreter terminates the current user program while displaying the error message below. Error message sample: ERL=38A4 ERR=34
This message indicates that an execution error occurred at address 38A4h and its error code is 34h. Both the address and error code are expressed in hexadecimal notation. The address corresponds to the address in the program list output by the Compiler, so you can pinpoint the program line where the execution error occurred. The error code 34h (52 in decimal notation) means that the user program attempted to access a file not opened. The ERL and ERR functions described in an error-handling routine return the same values, 38A4h and 34h, respectively. Refer to Execution Errors on page A-1. Note: After handling trapped errors by the error-handling routine, do not use the RESUME statement to pass control back to the main routine with the different stack level. The return address from the user-defined functions or sub-routines are left on the stack, causing an execution error due to stack overflow. To prevent this, transfer control to the routine which caused the interrupt in order to match the stack level, then jump to another desired routine.
Programming for Trapping Errors To trap errors, use the ON ERROR GOTO statement to designate the error-handling routine (to which control is to be transferred if an execution error occurs) by the label. ON ERROR GOTO err01 : : (Main routine) : : END
9-3
Page 108
PDT 1100 Terminal Programmer’s Guide err01 (Error-handling routine) PRINT “*** error ***” PRINT ERR,HEX$(ERL) RESUME NEXT
If an execution error occurs in the main routine, the above program executes the errorhandling routine specified by label err01 in the ON ERROR GOTO statement. In the error-handling routine, the ERL and ERR functions pinpoint the address where the error occurred and the error code, respectively. Note: According to the error location and error code, troubleshoot the programming error and correct it for proper error handling. The RESUME statement may pass control from the error-handling routine back to any specified statement as listed below. Table 9-2. RESUME Statement RESUME Statement
Description
RESUME or RESUME 0
Resumes program execution with the statement that caused the error.
RESUME NEXT
Resumes program execution with the statement immediately following the one that caused the error.
RESUME label
Resumes program execution with the statement designated by label.
Event (of Keystroke) Trapping If the function key previously specified for keystroke trapping is pressed, event trapping cause an interrupt to transfer control from the current program to the specified event-handling routine. This trapping facility checks whether the function key is pressed or not between every execution of the statements.
Programming for Trapping Keystrokes To trap keystrokes, use both the ON KEY...GOSUB and KEY ON statements. The ON KEY...GOSUB statement designates the key number of the function key to be trapped and the event-handling routine (to which control is to be transferred if a specified function key is pressed) in its label. The KEY ON statement activates the designated function key. This trapping cannot take effect
9-4
Page 109
Event Polling and Error/Event Trapping until both the ON KEY...GOSUB and KEY ON statements have been executed. The keystroke of an unspecified function key or numerical key cannot be trapped. The following program sample traps keystroke of function key F1, F2, or F3 (these keys are numbered 1, 2, and 3, respectively). ON KEY (1) GOSUB sub1 ON KEY (2) GOSUB sub2 ON KEY (3) GOSUB sub3 KEY (1) ON KEY (2) ON KEY (3) ON : : (Main routine) : : END sub1 (Event-handling routine 1) RETURN sub2 (Event-handling routine 2) RETURN sub3 (Event-handling routine 3) RETURN
The RETURN statement in the event-handling routine returns control to the statement immediately following that statement where the keyboard interrupt occurred. Even if a function key is assigned a null string by the KEY statement, pressing the function key causes a keyboard interrupt when the KEY ON statement activates the function key. If function keys specified for keystroke trapping are pressed during execution of the following statements or functions relating keyboard input, this trapping facility operates as described below. Table 9-3. Statement and Function Statements or Functions INPUT statement
Keystroke Trapping Ignores the entry of the pressed key and causes no interrupt.
LINE INPUT statement Same as above.
9-5
Page 110
PDT 1100 Terminal Programmer’s Guide
Table 9-3. Statement and Function (Continued) Statements or Functions
Keystroke Trapping
INPUT$ function
Same as above.
INKEY$ function
Ignores the entry of the pressed key, but causes an interrupt.
9-6