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:

  • Classes in VBScript Classes in VBScript Here is an example that shows how we can create a class in QTP. Once we define the class, we can create its objects and then access its method and properties. 'declare the class book. Class Bo… Read More
  • Maths functions in vbscript Maths functions in vbscript Below is the list of all maths functions in vb script Abs  Atn  Cos  Exp  Fix  Int  Log  Rnd  Sgn  Sin  Sqr  Tan  round Let us … Read More
  • Regular Expressions in vb script example Regular Expressions in vb script example Regular expressions BasicsDefinition :A regular expression is a pattern of characters(meta characters and special characters). General Applications of Regular Expression… Read More
  • Dictionary Object in vb script Example Dictionary Object in vb script Example Dictionary object is used to store the data in key-item pairs in qtp.A Dictionary object is just like an associative array.It stores the data in the form of key-item pairs.Each k… Read More
  • File system object in vb script File system object in vb script Filesystemobject can be used to work with drives, folders, and files.Filesystemobject  has methods and properties that allow us to create, delete, gain information about, and gener… Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

150,592

Blog Archive