Some examples of program exception/errors are: division by zero, SQRT of
a negative number, invalid array index, error on a CALL, error return from
called program, and start position or length out of range for a string operation.
They can be handled in one of the following ways:
The operation code extender 'E' can be specified for some operation codes.
When specified, before the operation begins, this extender sets the %ERROR
and %STATUS built-in functions to return zero. If an exception/error occurs
during the operation, then after the operation %ERROR returns '1' and %STATUS
returns the program status. The optional program status data structure is
updated with the exception/error information. You can determine the action
to be taken by testing %ERROR and %STATUS.
An indicator can be specified in positions 73 and 74 of the calculation
specifications for some operation codes. This indicator is set on if an
exception/error occurs during the processing of the specified operation.
The optional program status data structure is updated
with the exception/error information. You can determine the action to be
taken by testing the indicator.
ON-ERROR groups can be used to handle errors for statements
processed within a MONITOR block. If an error occurs when a statement is
processed, control passes to the appropriate ON-ERROR group.
You can create a user-defined ILE exception handler that will take control
when an exception occurs. For more information, see IBM Rational Development Studio for i: ILE RPG Programmer's Guide.
A program exception/error subroutine can be specified.
You enter *PSSR in factor 1 of a BEGSR operation to specify this subroutine.
Information regarding the program exception/error is made available through
a program status data structure that is specified with an S in position 23
of the data structure statement on the definition specifications. You can
also use the %STATUS built-in function, which returns the most recent value
set for the program or file status.
If the indicator, 'E' extender, monitor block, or
program exception/error subroutine is not present, program exception/errors
are handled by the RPG IV default error handler.