Compaq AA-PWCBD-TE Computer Accessories User Manual


 
Lexical Elements of the DEC Text Processing Utility Language
4.9 Reserved Words
4.9.4.14 Error Handling
A block of code starting with ON_ERROR and ending with ENDON_ERROR
defines the actions that are to be taken when a procedure fails to execute
successfully. Such a block of code is called an error handler. An error handler
is an optional part of a DECTPU procedure or program. An error handler traps
WARNING and ERROR status values. (See SET (INFORMATIONAL) and SET
(SUCCESS) in the DEC Text Processing Utility Reference Manual for information
on handling informational and success status values.)
It is good programming practice to put an error handler in all but the simplest
procedures. However, if you omit the error handler, DECTPU’s default error
handling behavior is as follows:
If you press Ctrl/C, DECTPU places an error message in the message buffer,
exits from all currently active procedures (in their reverse calling order), and
returns to the ‘‘wait for next key’’ loop.
If an error or warning is generated during a CALL_USER routine, ERROR is
set to the keyword that represents the failure status of the routine, ERROR_
LINE is set to the line number of the error, and ERROR_TEXT is set to the
message associated with the error or warning. DECTPU places the message
in the message buffer, then resumes execution at the statement after the
statement that generated the error or warning.
For other errors and warnings, ERROR is set to the keyword that represents
the error or warning, ERROR_LINE is set to the line number of the error, and
ERROR_TEXT is set to the message associated with the error or warning.
DECTPU places the message in the message buffer, then resumes execution
at the statement after the statement that generated the error or warning.
In a procedure, the error handler must be placed at the beginning of a
procedure—after the procedure parameter list, the LOCAL or CONSTANT
declarations, if present, and before the body of the procedure. In a program,
the ON_ERROR language statements must be placed after all the global
declarations (PROCEDURE, CONSTANT, and VARIABLE) and before any
executable statements. Error statements can contain any DECTPU language
statements except other ON_ERROR statements.
There are three DECTPU lexical elements that are useful in an error handler:
ERROR, ERROR_LINE, and ERROR_TEXT.
ERROR returns a keyword for the error or warning. The DEC Text Processing
Utility Reference Manual includes information on the possible error and warning
keywords that each built-in procedure can return.
ERROR_LINE returns the line number at which the error or warning occurs. If
a procedure was compiled from a buffer or range, ERROR_LINE returns the line
number within the buffer. (This may be different from the line number within
the procedure.) If the procedure was compiled from a string, ERROR_LINE
returns 1.
ERROR_TEXT returns the text of the error or warning, exactly as DECTPU
would display it in the message buffer, with all parameters filled in.
After the execution of an error statement, you can choose where to resume
execution of a program. The options are the following:
ABORT—This language statement causes an exit back to the DECTPU ‘‘wait
for next key’’ loop.
Lexical Elements of the DEC Text Processing Utility Language 4–23