The words EXCEPTION and ERROR are synonymous and may be used interchangeably.

USE Statement - Format
>>-USE--+--------+--AFTER--+----------+--+-EXCEPTION-+---------->
'-GLOBAL-' '-STANDARD-' '-ERROR-----'
.-------------.
V |
>--PROCEDURE--+----+--+---file-name-1-+-+----------------------><
'-ON-' +-INPUT-----------+
+-OUTPUT----------+
+-I-O-------------+
'-EXTEND----------'
- file-name-1
- Valid for all files. When this option is specified, the procedure is
executed only for the file(s) named. No file-name can refer to a sort or
merge file. For any given file, only one EXCEPTION/ERROR procedure may 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.
IBM Extension
The file-name phrase is also valid for TRANSACTION files.
End of IBM Extension
- INPUT
- Valid for all files. When this option is specified, the procedure is
executed for all files 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 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 that get an error.
IBM Extension
The I-O phrase is also valid for TRANSACTION files.
End of IBM Extension
- EXTEND
- When this option is specified, the procedure is executed for all files
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 status key 1
to be set to 9. (See Status Key.)
The EXCEPTION/ERROR procedures are activated when an input/output error
occurs during execution of a ACQUIRE, DROP, READ, WRITE, REWRITE, START, OPEN,
CLOSE, or DELETE statement. To determine what conditions are errors, see Common Processing Facilities.
After execution of the EXCEPTION/ERROR Declarative procedure, control is
returned to the statement immediately following the input/output statement
which caused the error.
Within a declarative procedure, there must be no reference to any nondeclarative
procedures. In the nondeclarative portion of the program, there must be no
reference to procedure-names that appear in an EXCEPTION/ERROR declarative
procedure, except that PERFORM statements may refer to an EXCEPTION/ERROR
procedure or to procedures associated with it.
Within an EXCEPTION/ERROR declarative procedure, no statement should be
included that would cause execution of a USE procedure that had been previously
invoked and had not yet returned control to the invoking routine.