Error handling in VBScript
VBScript provides below statements and keywords to handle errors.
- on error resume next
- Err object - err.description, err.number
Sample code to handle the error is given below
If err.number <> 0 Then print err.description else print "there was no error in above statement" end if
Whenever any error occurs in the script, We get the message window with detailed description of the error.
But when we are executing the scripts, we do not want this message box to appear to come as this will halt the execution of the script.
To prevent message box from appearing, we use below statement above the block of code.
On error resume next
----------
----------
more statements
With On error resume next in place, VBScript runs even though error exists in the code. We can capture those errors using Err object as stated earlier.
When you are debugging the scripts, you should not use On error resume next statement as it will suppress the errors and you will not be able to figure out the issue in your script.
0 comments:
Post a Comment