The VBScript Network and Systems Administrator's Cafe

Sep 26 2008   7:54PM GMT

VBScript Statements: Explanation of the On Error Statement

Jerry Lees Jerry Lees Profile: Jerry Lees

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

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: