Ü  ON-ERROR (On Error)

·         ON-ERROR follows the MONITOR opcode which is used for trapping errors.

 

·         If no error indicator or 'E' extender is present and the code that generates the exception is in the MONITOR block of a MONITOR group, control will pass to the on-error section of the MONITOR group.

·         V5R1 makes the introduction of a MONITOR group: it allows you to monitor a number of statements for potential errors, as opposed to checking them one at a time.

·         The code for which you want to trap exception errors is placed in a MONITOR group. If an exception/error is issued for any of the operations (between the MONITOR and the first ON-ERROR operation), control passes to the first ON-ERROR statement.

·         After the MONITOR statement, control passes to the next statement.

·         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.

·         ON-ERROR supports four types of error catching as given below.

 

Monitor;

// Code to monitor

On-Error statuscode1 : statuscode2 :statuscode3;

// Handle Error related to statuscode1 or statuscode2 or statuscode3

On-Error *FILE;

// Handles all file-error status codes, from 01000 to 09999

On-Error *PROGRAM;

// Handles all program-error status codes, from 00100 to 00999

On-Error *ALL;

// Handles both program-error and file-error codes, from 00100 to 09999. This is the  

   default.

EndMon;

 

Example


Columns . . . :    6  80               Browse                                    AMITCC/QRPGLESRC
SEU==>                                                                                 MONITORPG2
FMT H  HKeywords++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*************** Beginning of data *******************************************************
0001.00 HOPTION(*SRCSTMT)
0002.00 FCUST      UF A E             DISK    USROPN
0003.00
0004.00  *_________________________________________________________
0005.00  *
0006.00 C                   MONITOR
0007.00  *_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0008.00  *
0009.00 C                   MONITOR
0010.00 C     1             SETLL     CUSTR
0011.00 C                   ON-ERROR  1211     >>>> If the error is ‘file CUST not OPEN’, then
0012.00 C                   OPEN      CUST                     open the file CUST
0013.00 C                   ENDMON
0014.00  *_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0015.00  *
0016.00 C                   MONITOR
0017.00 C                   EVAL      CSNAME='OOO'
0018.00 C                   UPDATE    CUSTR
0019.00 C                   ON-ERROR  1215   >>> If the error is ‘Update without prior INPUT/READ
0020.00 C                   READ(E)   CUST            operation’, then READ the file.
0021.00 C                   EVAL      CSNAME='OOO'
0022.00 C                   UPDATE(E) CUSTR
0023.00 C                   ENDMON
0024.00  *_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0025.00  *
0026.00 C                   ON-ERROR  *FILE
0027.00 C                   DUMP(A)         >>>> If the error is ‘any unhandled file error’ then
0028.00 C                   ON-ERROR                        take the DUMP’.
0029.00 C                   DUMP(A)
0030.00 C                   ENDMON
0031.00  *_________________________________________________________
0032.00  *
0033.00 C                   SETON                                        LR
0034.00  *
0035.00  *
****************** End of data ***********************************************************

 











User Comments:



Subscribe

.  


Copyright © www.go4as400.com, 2013-2023. Copyright notice   Terms of services   Privacy policy