我想要抑制在我的VBS登录脚本中可能出现的所有错误。
我可以用以下方式包围整个500行脚本吗:
我可以用以下方式包围整个500行脚本吗:
On Error Resume Next
'[... whole script (~500 lines of code) ...]
On Error GoTo 0
On Error Resume Next
'[... whole script (~500 lines of code) ...]
On Error GoTo 0
...
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
这种方法确保了在错误发生后的代码行不会被执行。