PLI Exception Handling (ON CONDTION)

本文介绍PL/I编程语言中异常处理的基本概念,包括条件的发生、状态、处理动作的更改及模拟等。探讨如何通过ON语句指定特定条件发生时的动作,并讨论了条件的状态管理及调试工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Exception Handling (ON CONDTION)

1.  A CONDITION is the occurrence within a PL/I program that causes a program interrupt.

l         In the absence of a program specifying an action, for most conditions the standard system action is to print a message, raise the ERROR condition and then terminate the PL/I program and return control to the OS.

l         In PL/I the ON statement is used to specify action to be taken when any subsequent occurrence of a specified condition causes a program interrupt. e.g.

ON ENDFILE(SYSIN)

BEGIN;

PUT SKIP(3) LIST(TOTAL);

PUT PAGE LIST(NO OF RECORDS PROCESSED,COUNT)

END_OF_FILE = ‘YES’;

END;

 2.  Status of conditions:

l         Some conditions are always enabled unless explicitly disabled, others are disabled unless explicitly enabled.

l         When a condition is enabled:

- Programmer defined action takes place

- System defined action takes place.

l         The following conditions are always enabled: CONVERSION, FIXEDOVERFLOW, OVERFLOW, UNDERFLOW, ZERODIVIDE.

l         The SIZE condition is disabled unless enabled by the programmer.

   3.  Changing the status of conditions (Enable or Disable)

     (NOFIXEDOVERFLOW):CALC:SUM = A + B + C;

l         Fixedoverflow condition is disabled.

l         CALC is the label name.

l         If it is desired to enable or disable condition execution in the entire program then specify the CONDITION prefix in the procedure statement.

e.g. (SIZE,NOFIXEDOVERFLOW):PROG1 : PROC OPTIONS( MAIN );

  4.  Changing the ACTION taken.

l         It is possible to specify more than one ON statements for the same condition in a program.

         ON ENDFILE(SYSIN)    CALL ERROR_RT;

..

..

         ON ENDFILE(SYSIN) CALL NORMAL_END_OF_JOB;

l         If after having supplied your own ON-unit for a condition, you wish to return to the standard system action for that on unit, simply specify another ON statement with the keyword SYSTEM.

   5.  Simulating conditions (主动触发异常,类似java中的throw exception)

l         The programmer can simulate the occurrence of a condition through the use of the SIGNAL statement.

l         Execution of the signal statement has the same affect as if the condition has actually occurred.

l         If the signaled condition is not enabled the SIGNAL statement is treated as a NULL statement.

e.g.

ON ENDFILE(SYSIN) MORE_DATA = ‘NO’;

ON ENDPAGE(PRINTR)

      BEGIN;

      PUT PAGE LIST(‘’, Weekly status report, SUBSTR(TODAY,3,2) || /  ||

                   SUBSTR(TODAY,5,2) || / || SUBSTR(TODAY,1,2),                                                          ‘PAGE’||PAGE_NUMBER );

      PAGE_NUMBER = PAGE_NUMBER + 1;

      END;

TODAY = DATE;

PAGE_NUMBER = 1;

OPEN FILE(PRINTR) PAGESIZE(45);

SIGNAL ENDPAGE(PRINTR);

MORE_DATA = YES;

GET LIST(DATA);

DO WHILE (MORE_DATA);

      CALL PROCESS_DATA;

      CALL PRINT_DATA;

      GET LIST(DATA);

END;

6.       Some useful Debugging tools:

PUT DATA:    It causes all the variables known to the program at the point of the PUT statement to be outputed in the form of assignment statements. Since this is at the expense of considerable programming overhead, it should be used only for debugging.  e.g.

   ON ERROR

      BEGIN;

             ON ERROR SYSTEM ;

            PUT DATA;

      END;

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值