COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-290
USE AFTER EXCEPTION
It is usually best to write USE statements that explicitly reference individual files,
because this gives you better control over the handling of exceptions. The
declarative called by implicit reference has no simple way to determine the identity
of the file that generated an exception. The management of this generic sort of
exception handling can be difficult, particularly when program maintenance might
introduce additional files, or in nested programs when a GLOBAL declarative is
active.
•
Precedence Rules for Nested Programs
When a program contains other programs, these precedence rules apply. When
the run-time routines detect an I-O exception, they apply these rules (in the order
indicated) to select and perform only the first declarative procedure that qualifies.
1. If the program in which the exception-causing statement occurred contains an
appropriate declarative, use it.
2. If no declarative in that program is appropriate, check the next containing
program (the next one outward in the nesting). If the containing program
contains an appropriate declarative in which the GLOBAL phrase is specified,
use it.
3. Repeat Item 2 until the outermost program has been checked. If no qualifying
declarative procedure has been found, none is executed.
An outer program can contain a GLOBAL declarative procedure to handle each
file, but a nested program can contain an overriding GLOBAL or local declarative
procedure that governs the handling of exceptions for certain files within the nested
program or any programs it contains.
•
File Status and GUARDIAN-ERR Special Register
For information on file status and the special register GUARDIAN-ERR, see I-O
Status Code. A USE AFTER EXCEPTION procedure can base its activity on the
values of these data items.