What does the “On Error Resume Next” statement do?

后端 未结 7 2564
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 07:54

I came to some VBScript examples, and I saw the statement On Error Resume Next basically at the beginning of the script.

What does it do?

相关标签:
7条回答
  • 2020-11-29 08:41

    It means, when an error happens on the line, it is telling vbscript to continue execution without aborting the script. Sometimes, the On Error follows the Goto label to alter the flow of execution, something like this in a Sub code block, now you know why and how the usage of GOTO can result in spaghetti code:

    Sub MySubRoutine()
       On Error Goto ErrorHandler
    
       REM VB code...
    
       REM More VB Code...
    
    Exit_MySubRoutine:
    
       REM Disable the Error Handler!
    
       On Error Goto 0
    
       REM Leave....
       Exit Sub
    
    ErrorHandler:
    
       REM Do something about the Error
    
       Goto Exit_MySubRoutine
    End Sub
    
    0 讨论(0)
提交回复
热议问题