ON-EXCP (On Exception)

Free-Form Syntax ON-EXCP{(C)} message-id1 {:message-id2 ... }
Code Factor 1 Extended Factor 2
ON-EXCP{(C)}   message-id1 {:message-id2 ... }

The ON-EXCP operation begins an on-exception block, which is part of a monitor group. You can have both ON-EXCP operations and ON-ERROR operations in a monitor group, but the ON-EXCP operations must precede the ON-ERROR operations.

You specify which message IDs the on-exception block handles in the list of message IDs (message-id1:message-id2...) separated by colons.

Specify the (C) extender if you only want to handle exceptions sent to the procedure containing the monitor group. When the (C) extender is not specified, the ON-EXCP operation can handle unhandled exceptions from procedures called from the monitor block.

Any errors that occur within an on-exception block are not handled by the monitor group. To handle errors, you can specify a monitor group within an on-exception block.

When all the statements in an on-exception block have been processed, control passes to the statement following the ENDMON statement.

If you want to monitor for a specific RPG status code, use the ON-ERROR operation code.

For examples of the ON-EXCP statement, see MONITOR (Begin a Monitor Group).

For more information, see Error-Handling Operations.

Monitor for the exception that causes an I/O operation to fail

When an I/O operation ends in error, RPG sends an RNX message for the status code associated with the error.

For I/O operations in the monitor block, you can monitor for either the RNX message sent by RPG or the CPF message sent by data management. However, for I/O operations in a program or procedure called from the monitor block, you can only monitor for the RNX message sent by RPG. The CPF message causing the error can only be monitored in the same procedure as the I/O operation.

For example, if message CPF501B is sent during an UPDATE operation indicating that an update operation was done without a prior input operation, RPG sends message RNX1221 to cause the operation to fail with status 1221.

If an ON-EXCP block monitors for message CPF501B, the ON-EXCP block for CPF501B gets control.

However, if an ON-EXCP block for message RNX1221 is specified before the ON-EXCP block for message CPF501B, the ON-EXCP block for message RNX1221 gets control.

See Using ON-EXCP to monitor for the exception causing an I/O error.