Using a MONITOR Group

A MONITOR group performs conditional error handling based on the status code. If an error occurs, control passes to the appropriate ON-ERROR group within the MONITOR group.

If all the statements in the MONITOR block are processed without errors, control passes to the statement following the ENDMON statement.

The MONITOR group can be specified anywhere in calculations. It can be nested within IF, DO, SELECT, or other MONITOR groups. The IF, DO, and SELECT groups can be nested within MONITOR groups.

If a MONITOR group is nested within another MONITOR group, the innermost group is considered first when an error occurs. If that MONITOR group does not handle the error condition, the next group is considered.

Level indicators can be used on the MONITOR operation, to indicate that the MONITOR group is part of total calculations. For documentation purposes, you can also specify a level indicator on an ON-ERROR or ENDMON operation but this level indicator will be ignored.

Conditioning indicators can be used on the MONITOR statement. If they are not satisfied, control passes immediately to the statement following the ENDMON statement of the MONITOR group. Conditioning indicators cannot be used on ON-ERROR operations individually.

If a MONITOR block contains a call to a subprocedure, and the subprocedure has an error, the subprocedure's error handling will take precedence. For example, if the subprocedure has a *PSSR subroutine, it will get called. The MONITOR group containing the call will only be considered if the subprocedure fails to handle the error and the call fails with the error-in-call status of 00202.

The MONITOR group does handle errors that occur in a subroutine. If the subroutine contains its own MONITOR groups, they are considered first.

Branching operations are not allowed within a MONITOR block, but are allowed within an ON-ERROR block.

A LEAVE or ITER operation within a MONITOR block applies to any active DO group that contains the MONITOR block. A LEAVESR or RETURN operation within a MONITOR block applies to any subroutine, subprocedure, or procedure that contains the MONITOR block.

On each ON-ERROR statment, you specify which error conditions the ON-ERROR group handles. You can specify any combination of the following, separated by colons:

nnnnn
A status code
*PROGRAM
Handles all program-error status codes, from 00100 to 00999
*FILE
Handles all file-error status codes, from 01000 to 09999
*ALL
Handles both program-error and file-error codes, from 00100 to 09999. This is the default.

Status codes outside the range of 00100 to 09999, for example codes from 0 to 99, are not monitored for. You cannot specify these values for an ON-ERROR group. You also cannot specify any status codes that are not valid for the particular version of the compiler being used.

If the same status code is covered by more than one ON-ERROR group, only the first one is used. For this reason, you should specify special values such as *ALL after the specific status codes.

Any errors that occur within an ON-ERROR group are not handled by the MONITOR group. To handle errors, you can specify a MONITOR group within an ON-ERROR group.

Figure 137. MONITOR Operation
 * The MONITOR block consists of the READ statement and the IF
 * group.
 * - The first ON-ERROR block handles status 1211 which
 *   is issued for the READ operation if the file is not open.
 * - The second ON-ERROR block handles all other file errors.
 * - The third ON-ERROR block handles the string-operation status
 *   code 00100 and array index status code 00121.
 * - The fourth ON-ERROR block (which could have had a factor 2
 *   of *ALL) handles errors not handled by the specific ON-ERROR
 *   operations.
 *
 * If no error occurs in the MONITOR block, control passes from the
 * ENDIF to the ENDMON.
C                  MONITOR
C                  READ       FILE1
C                  IF         NOT %EOF
C                  EVAL       Line = %SUBST(Line(i) :
C                                           %SCAN('***': Line(i)) + 1)
C                  ENDIF
C                  ON-ERROR   1211
C                   ... handle file-not-open
C                  ON-ERROR   *FILE
C                   ... handle other file errors
C                  ON-ERROR   00100 : 00121
C                   ... handle string error and array-index error
C                  ON-ERROR
C                   ... handle all other errors
C                  ENDMON


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