Thursday, January 3, 2019


Error handling in VBScript

VBScript provides below statements and keywords to handle errors.
  1. on error resume next
  2. 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 placeVBScript 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.


Related Posts:

  • Sub Procedures in VBScript example Code Sub Procedures in VBScript Sub Procedures in VBScript Sub procedures are used to perform the specific task. Sub procedures are used to increase the reusability of the code. Simple example of the Sub Procedures Suppo… Read More
  • Basic Syntax in VBScript Basic Syntax in VBScript Basic VBScript SyntaxRemember below points about VBScript Syntax. VBScript is loosely typed language that means you do not need to declare the variables with data type VBScript comments start … Read More
  • What is vbscript? What is vbscript? VBScript Intoduction Vb script is a scripting language used for performing administrative tasks in system programming.Vb script is a loosely typed language meaning we don't need to define the type of… Read More
  • Types of variables in Vbscript Types of variables in Vbscript Variables are storage locations in memory where we can store the the values.In vb script there are 3 types of variables. Scalar  - contains only one value. Array - contains many val… Read More
  • Data Types in vbscript Data Types in vbscript In vb script all variables are initialized with the data type called variant. But we can have below sub-types in vb script. In below table we have mentioned all sub data types in vb sc… Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

150,585

Blog Archive