1

OpenVMS DCL命令显示HELP ON EXAMPLE

例子

   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

4

1 回答 1

4

如果 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 NOON) 以不同方式处理此问题:

$ 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
于 2014-12-12T13:02:15.977 回答