ILE RPG Exception Handling

ILE RPG provides four types of exception handling mechanisms:

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:

  1. Specify an error indicator in positions 73 - 74 of the calculation specifications of the appropriate operation code.
  2. Specify the operation code extender 'E' for the appropriate operation code.
  3. Include the code that produces the exception within a MONITOR group.
  4. 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.
  5. 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.


[ Top of Page | Previous Page | Next Page | Contents | Index ]