PL/1 ON UNDEFINEDFILE
时间: 2023-09-30 21:02:19 浏览: 55
PL/1 ON UNDEFINEDFILE is a statement in the PL/1 programming language that enables or disables error handling for undefined files. When this statement is enabled, PL/1 will check for errors when opening, reading, writing, or closing a file that has not been previously defined. If an error is detected, PL/1 will generate an exception and allow the programmer to handle the error. If this statement is disabled, PL/1 will not check for errors and may cause the program to crash if it attempts to access an undefined file.
相关问题
ON UNDEFINEDFILE PL/1 怎么使用
UNDEFINEDFILE is a PL/1 compiler option that specifies the action to be taken when a program attempts to read from a file that has not been opened or has been closed unexpectedly.
To use UNDEFINEDFILE in PL/1, you need to specify it as a compiler option when compiling your program. Here's an example:
```
/* PL/1 program to demonstrate UNDEFINEDFILE */
OPTIONS UNDEFINEDFILE(ERROR);
DCL MYFILE FILE RECORD INPUT;
DCL MYVAR CHAR(10);
OPEN MYFILE(FILENAME('myfile.txt'));
READ MYFILE INTO(MYVAR);
CLOSE MYFILE;
END;
```
In this example, we have specified the UNDEFINEDFILE option as ERROR, which means that the program will terminate with an error message if it attempts to read from a file that has not been opened or has been closed unexpectedly.
You can also specify UNDEFINEDFILE as WARNING or IGNORE. If you specify it as WARNING, the program will issue a warning message but will continue executing. If you specify it as IGNORE, the program will ignore the error and continue executing as if nothing happened.
Note that UNDEFINEDFILE is a compiler option and not a PL/1 statement. Therefore, you need to specify it separately from your program code.
PL/1 ON OVERFLOW 的用法
PL/1是一种编程语言,ON OVERFLOW是一种PL/1语言的异常处理方式,用于在程序发生溢出错误时执行特定的操作。
ON OVERFLOW可以用在PL/1程序中的DO语句、LOOP语句、SELECT语句和SUBROUTINE语句中。其语法如下:
```
ON OVERFLOW statement;
```
其中,statement是要执行的语句。当程序在执行过程中发生了溢出错误时,PL/1会跳转到指定的statement语句进行处理。
例如,以下代码演示了在PL/1中使用ON OVERFLOW处理溢出错误的示例:
```
DCL I FIXED BINARY(15);
DO I = 1 TO 32767;
ON OVERFLOW
PUT SKIP LIST('Overflow error occurred.');
END;
PUT LIST(I);
END;
```
在上述代码中,当程序执行到I等于32767时,会发生溢出错误。此时,PL/1会跳转到ON OVERFLOW语句中的PUT语句,输出错误提示信息。然后程序会继续执行DO语句中的下一次循环。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)