EXCEPTION/ERROR declarative
The EXCEPTION/ERROR declarative specifies procedures for input/output exception or error handling that are to be executed in addition to the standard system procedures.
The words EXCEPTION and ERROR are synonymous and can be used interchangeably.
- file-name-1
- Valid for all files. When this option is specified, the procedure
is executed only for the files named. No file-name can refer to a
sort or merge file. For any given file, only one EXCEPTION/ERROR procedure
can be specified; thus, file-name specification must not cause simultaneous
requests for execution of more than one EXCEPTION/ERROR procedure.
A USE AFTER EXCEPTION/ERROR declarative statement specifying the name of a file takes precedence over a declarative statement specifying the open mode of the file.
- INPUT
- Valid for all files. When this option is specified, the procedure is executed for all files opened in INPUT mode or in the process of being opened in INPUT mode that get an error.
- OUTPUT
- Valid for all files. When this option is specified, the procedure is executed for all files opened in OUTPUT mode or in the process of being opened in OUTPUT mode that get an error.
- I-O
- Valid for all direct-access files. When this option is specified, the procedure is executed for all files opened in I-O mode or in the process of being opened in I-O mode that get an error.
- EXTEND
- Valid for all files. When this option is specified, the procedure is executed for all files opened in EXTEND mode or in the process of being opened in EXTEND mode that get an error.
The EXCEPTION/ERROR procedure is executed:
- Either after completing the system-defined input/output error routine, or
- Upon recognition of an INVALID KEY or AT END condition when an INVALID KEY or AT END phrase has not been specified in the input/output statement, or
- Upon recognition of an IBM®-defined condition that causes file status key 1 to be set to 9. (See File status key.)
After execution of the EXCEPTION/ERROR procedure, control is returned to the invoking routine in the input/output control system. If the input/output status value does not indicate a critical input/output error, the input/output control system returns control to the next executable statement following the input/output statement whose execution caused the exception.
An applicable EXCEPTION/ERROR procedure is activated when an input/output error occurs during execution of a READ, WRITE, REWRITE, START, OPEN, CLOSE, or DELETE statement. To determine what conditions are errors, see Common processing facilities.
A declarative procedure must not reference a nondeclarative procedure.
A PERFORM statement in a nondeclarative procedure can reference a declarative procedure; otherwise, a declarative procedure must not be referenced from a nondeclarative procedure.
You can include a statement that executes a previously called USE procedure that is still in control. However, to avoid an infinite loop, you must be sure that there is an eventual exit at the bottom.
EXCEPTION/ERROR procedures can be used to check the file status key values whenever an input/output error occurs.