抑制整个脚本的错误 [英] Suppress errors for the whole script

查看:134
本文介绍了抑制整个脚本的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要抑制我的VBS登录脚本中可能出现的所有错误。

I am want to suppress all the errors that could appear in my VBS logon script.

我可以使用以下内容包围全部500行脚本:

Can I surround the WHOLE 500 lines script with :

On Error Resume Next

'[... whole script (~500 lines of code) ...]

On Error GoTo 0


推荐答案

可以这样做 - 即使没有OEG0行 - 但是你不应该,因为脚本将继续执行第i行...最后,即使i-1行中的错误使所有的对这些行动中必要的前提条件的假设。您的策略与驾驶相媲美,避免被其他车辆的前灯所眩目。

You can do it - even without the OEG0 line - but you shouldn't, because the script will continue to execute lines i ... last, even if an error in line i-1 invalidates all your assumptions about necessary pre-conditions of the actions in those lines. Your strategy is comparable to driving with your eyes shut to avoid being dazzled by the headlights of other cars.

如果您无法对所选操作进行本地重新定义的错误处理 -

If you can't do locally resticted error handling for selected actions -

...
On Error Resume Next
  risky_action
  save Err
On Error GoTo 0
If ErrorOccurred Then
   something sensible
   If can't continue Then
      WScript.Quit 4711
   End If
End If
...

尝试摆脱

Sub Main()
  ... you 500 lines ...
End Sub 

On Error Resume Next
  Main
  If Err.Number Then
     WScript.Echo "aborted"
     WScript.Quit 4711
  End If

此方法确保错误后的行将不会执行。

This approach makes sure that the lines after an error won't be executed.

这篇关于抑制整个脚本的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆