gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:46:42 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com