ILE RPG provides four types of exception handling mechanisms:
An error indicator or an 'E' operation code extender handler
A MONITOR group
An error subroutine handler
A default exception handler
RPG categorizes exceptions into two classes, program and file; this determines
which type of error subroutine is called. Some examples of program exceptions
are division by zero, out-of-bounds array index, or SQRT of a negative number.
Some examples of file exceptions are undefined record type or a device error.
There are five ways for you to indicate that RPG should handle an exception.
You can:
Specify an error indicator in positions 73 - 74 of the calculation specifications
of the appropriate operation code.
Specify the operation code extender 'E' for the appropriate operation
code.
Include the code that produces the exception within a MONITOR
group.
Code a file error subroutine, which is defined by the INFSR
keyword on a file description specification, for file exceptions. The file
error subroutine must be coded in the same scope as the file; a global file
in a cycle module must have its subroutine in the cycle-main procedure, and
a local file must have its subroutine in the same subprocedure as the file.
You cannot code an INFSR for a global file that is used in a subprocedure.
Code a program error subroutine, which is named *PSSR, for program exceptions.
Note that a *PSSR is local to the procedure in which it is coded. This means
that a *PSSR in a main procedure will handle only those program errors associated
with the main procedure. Similarly, a *PSSR in a subprocedure will only handle
the errors in that subprocedure.