COBOL Manual for TNS and TNS/R Programs

Executing and Debugging HP COBOL Programs
HP COBOL Manual for TNS and TNS/R Programs522555-006
25-14
Run-Time Errors
Diagnostic Messages
When a run-time error occurs, the run-time routine that detects it sends a run-time
diagnostic message to the default output device. The run-time routine that detects the
error is either a HP COBOL run-time routine (if the program is running in the non-CRE
environment) or a CRE run-time routine (if the program is running in the CRE). The
default output device is the home terminal unless you changed it with the PARAM
EXECUTION-LOG command (see Specifying a Default Input-Output Device) or the
OUT option of the RUN command (see Specifying Default Input and Output Devices).
A run-time diagnostic message identifies the error, the process in which the error
occurred, and the loadfile from which the process was loaded. The error number and
format of a run-time diagnostic message depend on the run-time environment. For
details, see Section 48, Run-Time Diagnostic Messages.
One category of run-time diagnostic messages is not reported to the default output
device: input-output exceptions with I-O status codes less than “30” that your program
handles with its own error-handling procedures.
Error-Handling Procedures
In your HP COBOL program, you can define error-handling procedures with USE
AFTER EXCEPTION statements. When a file system error occurs, control passes to a
USE AFTER EXCEPTION statement, which can access two values to determine what
action to take. The first value is the I-O status code, which identifies the error; the
second value is that of the special register GUARDIAN-ERR, which identifies the
cause of the error.
One I-O error can have several possible causes; therefore, one I-O code status value
can be associated with several GUARDIAN-ERR values. For example, a WRITE
statement error (I-O code status value “24”) can be caused by a relative key that is out
of bounds (GUARDIAN-ERR value 23), a full file (GUARDIAN-ERR value 45), or an
invalid key (GUARDIAN-ERR value 46). The USE AFTER EXCEPTION statement can
interpret the value of GUARDIAN-ERR and act accordingly.
After a USE AFTER EXCEPTION statement executes, it returns control to the routine
that called it, except when the I-O status code is “4x ” or “90,” in which case the
process terminates abnormally.
For more information about the USE AFTER EXCEPTION statement and diagnosing
input-output errors, see USE AFTER EXCEPTION.