Condition Handling

System Condition: For all of the conditions, a standard system action exists as part of PL/I. In the absence of program specifying an action to be taken when conditions are detected, a standard system action will take place. For most conditions, the standard system action is to print a message and then raise the ERROR condition. The error condition is raised as a result of the standard system action. Standard system action refers to terminate the PL/I program and return control to the operating system.

Program specified Action: In some cases, we do not want the system to take its standard action in response to a given condition, as in case of end of file. Following are few conditions:

  1. End of File
  2. Conversion
  3. Size
  4. Zerodivide

ON ENDFILE(SYSIN)
  BEGIN;
    PUT SKIP LIST('No of Records Processed', COUNT);
    END_OF_FILE = YES;
  END;

The status of Conditions: Some conditions are always enabled unless explicitly disabled; others are disabled unless explicitly enabled.

(SIZE,NOFIXEDOVERFLOW);
PROG1:PROC OPTIONS(MAIN);

Simulating Conditions: Programmer can simulate the occurrence of a condition through the use of the signal statement. Execution of the signal statement has the same effect as if the condition had actually occurred.

SIGNAL condition; /* any condition like ENDFILE */

When the error condition is raised, program is about to be terminated, before termination, it might be useful to capture the contents of program variables so that we may better understand what has gone wrong in the program. Thus, the following might be useful.

ON ERROR
  BEGIN;
    ON ERROR SYSTEM;
    PUT DATA;
  END;

Within the begin block, the on error system statement tells the system that if an error condition is raised during the execution of statements with the begin block, take system action of terminating the program. Generally all program variables will be printed.

ONCODE and ONLOC: These two built-in functions can be useful.

DCL (ONCODE,ONLOC) BUILTIN;
ON ERROR
  BEGIN;
    PUT LIST(ONODE,ONLOC);
  END;

Back

Hosted by www.Geocities.ws

1