Take the 2-minute tour ×

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?

share|improve this question
It is a very powerful, but dangerous bit of syntax. Be very cautious using it. –  Nate Feb 4 '10 at 20:22
It makes more sense now. After some functions that can end up in error. They have a function called checkError after them. –  CarlosBlanco Feb 4 '10 at 20:37
add comment

4 Answers

up vote 24 down vote accepted

It basically tells the program when you encounter an error just continue at the next line.

share|improve this answer
add comment

When an error occurs, the execution will continue on the next line without interrupting the script.

share|improve this answer
add comment

It's worth noting that even when On Error Resume Next is in effect, the Err object is still populated when an error occurs, so you can still do C-style error handling.

On Error Resume Next


If Err Then
    WScript.StdErr.WriteLine "error " & Err.Number
    WScript.Quit 1
End If

On Error GoTo 0
share|improve this answer
add comment

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


   REM Disable the Error Handler!

   On Error Goto 0

   REM Leave....
   Exit Sub


   REM Do something about the Error

   Goto Exit_MySubRoutine
End Sub

Hope this helps, Best regards, Tom.

share|improve this answer
VBScript doesn't support the On Error Goto Label syntax, only On Error Goto 0. –  Helen Feb 4 '10 at 20:44
add comment

Your Answer


