error-handling - 第一次错误后处理DCL ON ERROR Action ?

标签 error-handling openvms dcl

OpenVMS DCL命令HELP ON EXAMPLE显示:

ON

Examples

   1.$ ON SEVERE_ERROR THEN CONTINUE

     A command procedure that contains this statement continues
     to execute normally when a warning or error occurs during
     execution. When a severe error occurs, the ON statement signals
     the procedure to execute the next statement anyway. Once
     the statement has been executed as a result of the severe
     error condition, the default action (ON ERROR THEN EXIT) is
     reinstated.


根据帮助,如果[-]x.for[-]y.for都不存在,那么将不执行最后两行:
$ on error then $ continue
$ rename [-]x.for []
$ rename [-]y.for []
$ type *.for

是否可以像在第一行中那样在脚本的每一行之间不放置ON ERROR语句来设置ON ERROR处理?

最佳答案

如果发生ON ERROR,则必须重新建立它。看起来像你
不知道是否存在任何文件。所以ON ERROR需要是
在第一个失败的命令后重新建立。

您可以在子例程中执行此操作,例如:

$ on error then $ gosub on_error
$ rename [-]x.for []
$ rename [-]y.for []
$ on error then $ exit
$ type *.for
$ exit
$
$ on_error:
$ on error then $ gosub on_error
$ return

另外,您可以通过禁用错误检查(SET
中午):
$ set noon
$ rename [-]x.for []
$ rename [-]y.for []
$ set on
$ type *.for

或仅针对严重错误建立错误处理(ON SEVERE_ERROR):
$ on severe_error then $ exit
$ rename [-]x.for []
$ rename [-]y.for []
$ on error then $ exit
$ type *.for

关于error-handling - 第一次错误后处理DCL ON ERROR Action ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27434430/

相关文章:

edi - 如何设置 OpenVMS VM 环境

migration - 将 RMS 迁移到 RDB

Java BufferedReader openvms

openvms - 如何在 HP openVMS DCL 中启用区分大小写?

sockets - OpenVMS 下 SAS 中套接字的错误处理

php - PHP关闭所有错误,但将错误保存到error_log

php - PHP-包含或要求在oop的类文件中不起作用

python - 有什么方法可以返回我猜对的数字并在其后添加文本?