VBScript Statements: Explanation of the On Error Statement - The VBScript Network and Systems Administrator's Cafe

The VBScript Network and Systems Administrator's Cafe

Sep 26 2008   7:54PM GMT

VBScript Statements: Explanation of the On Error Statement



Posted by: Jerry Lees
VBScript Statements, Error control, on error

The on error statement allows you to somewhat control how the scripting engine handles errors in the scripts you write. It allows you to turn error handling on and off for the scripting engine so that you can handle them in your script.

 The Statement essentially has two ways it is used. First to turn off the script engine error checking:

On Error Resume Next

The second is to turn it on, thereby allowing the script engine to stop execution of a script when an error is encountered. Like so:

On Error Goto 0

One word of caution, It is very tempting to simply place “On error resume next” in a complex script block and not worry about annoying hard to find errors. However, It is generally better to try to find the source of the errors since ignoring the errors can cause unintended consequences– or at the very least difficult to find issues in another piece of code.

In general, if you use On Error Resume Next you should always check for errors and handle them in your code somehow. 

Comment on this Post


You must be logged-in to post a comment. Log-in/Register