error-handling - 抑制整个脚本的错误

标签 error-handling vbscript gpo

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

我可以用以下内容包围整个 500 行脚本:

On Error Resume Next

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

On Error GoTo 0

最佳答案

可以 这样做 - 即使没有 OEG0 行 - 但您不应该这样做,因为脚本将继续执行第 i ... 最后行,即使第 i-1 行中的错误使您对操作的必要前提条件的所有假设无效在那些行中。你的策略就像是闭着眼睛开车以避免被其他汽车的大灯刺眼。

如果您无法对所选操作进行本地限制性错误处理 -

...
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

这种方法确保不会执行错误后的行。

关于error-handling - 抑制整个脚本的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13627425/

相关文章:

error-handling - 如何在Odoo中调试错误消息

vbscript - 引用 Internet Explorer - 使用 Internet Explorer 对象模型

gpo - 如何使用GPO永久禁用Windows Defender实时保护?

c++ - 如何获取应用于本地工作站的组策略对象列表

asp.net-mvc - MVC中的自定义错误处理问题

c++ - 具有 union 返回类型的函数调用

postgresql - 错误: invalid input syntax for type numeric: “N/A” … nice but which column?

json - 任何用于在 Classic ASP 中解析 JSON 的好库?

dictionary - 读取txt文件并将所有单词放入字典中

powershell - 基于 GPO DisplayName 而不是 Id 的备份 GPO