Understanding ON ERROR in VBScript

后端 未结 3 1947
栀梦
栀梦 2020-12-21 14:24

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 ne         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 15:17

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

    On Error Goto 0
    

    vbscript handles errors. Your program crashes on errors.

    On Error Resume Next
    

    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
    

    In VB6 and VBA there is also

    On Error Goto LineNumber (or a label)
    

提交回复
热议问题