免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2549 | 回复: 5
打印 上一主题 下一主题

错误处理操作-出自ibm [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-12-12 09:53 |只看该作者 |倒序浏览
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).



  1. /free
  2.    MONITOR;                           _
  3.        OPEN   FILE;                    |
  4.        DOW    getNextRecord ();        |
  5.          X = X + 1;                    +-- This is the monitor block
  6.          nameList(X) = name;           |
  7.        ENDDO;                          |
  8.        CLOSE  FILE;                   _|
  9.    ON-ERROR   1216;                   _
  10.        DSPMSG                          |
  11.           ('Error opening file FILE'   |
  12.          : %status);                   +-- First on-error block
  13.        RETURN;                        _|
  14.    ON-ERROR   121;                    _
  15.        DSPMSG                          |
  16.           ('Array NAME is too small'   +-- Second on-error block
  17.          : %status);                   |
  18.        RETURN;                        _|
  19.    ON-ERROR   *ALL;                   _
  20.        DSPMSG                          |
  21.           ('Unexpected error'          +-- Final catch-all on-error block
  22.          : %status);                   |
  23.        RETURN;                        _|
  24.    ENDMON;                            --- End of MONITOR group
  25. /end-free
复制代码

评分

参与人数 1可用积分 +1 收起 理由
居士 + 1

查看全部评分

论坛徽章:
0
2 [报告]
发表于 2005-12-12 10:54 |只看该作者
异常处理操作符代码是
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

论坛徽章:
0
3 [报告]
发表于 2005-12-12 12:56 |只看该作者
好~~~

Monitor group补充完整了。

论坛徽章:
0
4 [报告]
发表于 2005-12-12 17:58 |只看该作者
顶!

论坛徽章:
0
5 [报告]
发表于 2005-12-12 20:57 |只看该作者
收入精华吧。。。

论坛徽章:
0
6 [报告]
发表于 2005-12-13 13:03 |只看该作者
不错不错!支持
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP