首页 > 学技术 > 技术网文 > IBM AS400应用论坛 > 正文

[精华] 错误处理操作-出自ibm


来源 chinaunix.net 酷勤网整理

The exception-handling operation codes are: 

MONITOR (Begin a Monitor Group) 
ON-ERROR (On Error) 
ENDMON, as described in ENDyy (End a Structured Group) 
These operation codes are available in both the traditional syntax and free-form syntax. 

MONITOR, ON-ERROR and ENDMON are used to code a monitor group. The monitor group consists of a monitor block, followed by one or more on-error blocks, followed by ENDMON. 

The monitor block contains the code that you think might generate an error. The on-error blocks contain the code to handle errors that occur in the monitor block. 

A monitor block consists of a MONITOR operation followed by the operations that will be monitored. An on-error block consists of an ON-ERROR operation, with a list of status codes, followed by the operations that will be performed if an error in the monitor block generates any of the listed status codes. 

When an error occurs in the monitor block and the operation has an (E) extender or an error indicator, the error will be handled by the (E) extender or the error indicator. If no indicator or extender can handle the error, control passes to the on-error block containing the status code for the error. When the on-error block is finished, control passes to the ENDMON. If there is no on-error block to handle the error, control passes to the next level of exception handling (the *PSSR or INFSR subroutines, or the default error handler). 



/free
   MONITOR;                           _
       OPEN   FILE;                    |
       DOW    getNextRecord ();        |
         X = X + 1;                    +-- This is the monitor block
         nameList(X) = name;           |
       ENDDO;                          |
       CLOSE  FILE;                   _|
   ON-ERROR   1216;                   _
       DSPMSG                          |
          ('Error opening file FILE'   |
         : %status);                   +-- First on-error block
       RETURN;                        _|
   ON-ERROR   121;                    _
       DSPMSG                          |
          ('Array NAME is too small'   +-- Second on-error block
         : %status);                   |
       RETURN;                        _|
   ON-ERROR   *ALL;                   _
       DSPMSG                          |
          ('Unexpected error'          +-- Final catch-all on-error block
         : %status);                   |
       RETURN;                        _|
   ENDMON;                            --- End of MONITOR group
/end-free




 wildfish 回复于:2005-12-12 10:54:39

异常处理操作符代码是
MONITOR(开始一个Monitor组)
ON-ERROR(错误时)
ENDMON(Monitor的配对符)
这些操作符在传统语法和自由格式里面都是可用的

MONITOR,ON-ERROR 和ENDMON 被用于编写一个监控组。监控组包含一个监控代码块,
跟着是一个或者多个ON-ERROR代码块,最后是ENDMON

监控代码块包围了你认为可能会产生错误的代码。ON-ERROR代码块包含了处理Monitor到的错误的代码。

一个监控块包含一个跟在需要被监控的操作后的MONITOR操作。一个ON-ERROR块包含一个ON-ERROR操作,
由一系列的状态代码,如果监控块监测到所列的状态代码,随后的ON-Error的代码将会被执行。

当一个错误发生在监控块内并且操作符有一个(E)扩展符或者一个错误指示器,错误就会北(E)或者
指示符处理。如果没有指示符或者扩展符,错误将会被Monitor捕捉,控制被传递到ON-ERROR中,
传递的信息包含错误的状态码。当On-Error块被执行完毕,控制转到ENDMON.如果没有ON-ERROR块处理
错误,控制会被传递到下一个级别的异常处理。(*PSSR 或者INFSR的subrountine,或者默认的错误处理)

代码示例
/free
   MONITOR;                           _
       OPEN   FILE;                    |
       DOW    getNextRecord ();        |
         X = X + 1;                    +-- This is the monitor block
         nameList(X) = name;           |
       ENDDO;                          |
       CLOSE  FILE;                   _|
   ON-ERROR   1216;                   _
       DSPMSG                          |
          ('Error opening file FILE'   |
         : %status);                   +-- First on-error block
       RETURN;                        _|
   ON-ERROR   121;                    _
       DSPMSG                          |
          ('Array NAME is too small'   +-- Second on-error block
         : %status);                   |
       RETURN;                        _|
   ON-ERROR   *ALL;                   _
       DSPMSG                          |
          ('Unexpected error'          +-- Final catch-all on-error block
         : %status);                   |
       RETURN;                        _|
   ENDMON;                            --- End of MONITOR group
/end-free


 qingzhou 回复于:2005-12-12 12:56:59

好~~~

Monitor group补充完整了。


 riancy1106 回复于:2005-12-12 17:58:44

顶!


 michael9406 回复于:2005-12-12 20:57:12

收入精华吧。。。


 coolk 回复于:2005-12-13 13:03:00

不错不错!支持




原文链接:http://bbs.chinaunix.net/viewthread.php?tid=667048
转载请注明作者名及原文出处



收藏本页到: