理解 VBScript 中的 ON ERROR [英] Understanding ON ERROR in VBScript

查看:29
本文介绍了理解 VBScript 中的 ON ERROR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改一个 vbscript 并按照指示将其转换为 Powershell.我的函数 SearchAD 上有一段代码块,带有 On Error.

I am trying to modify a vbscript and convert it to Powershell as instructed. I have a block of code on my function SearchAD with On Error.

on error resume next
Set objRS = command.execute

SearchAD = objRS.RecordCount
on error goto 0

我的问题是代码的哪一部分可以触发 RESUME Next,哪一部分用于 GOTO 0.

My question would be is what part of the code can trigger RESUME Next and what part is for GOTO 0.

推荐答案

在 VBScript 中有两种错误状态(在其他 VB 中为三种).

In VBScript there are two error states (three in other VBs).

On Error Goto 0

vbscript 处理错误.您的程序因错误而崩溃.

vbscript handles errors. Your program crashes on errors.

On Error Resume Next

VBScript 设置 err 对象但不引发错误.您需要在可能引发错误的每一行之后放置

VBScript sets the err object but doesn't raise an error. You are required to put after every line that may raise an error

If err.number <> 0 then 
    FreakoutAndFixTheError
    err.clear
    wscript.quit 'if you can't fix
End If

在 VB6 和 VBA 中也有

In VB6 and VBA there is also

On Error Goto LineNumber (or a label)

这篇关于理解 VBScript 中的 ON ERROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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