0 Shares 1662 Views 3 Comments

Error Handling in VBScript

Mar 31, 2013
1662 Views 3

ErrorHandlingError handling is the way for responding to occurrence of some unexpected situation that arrives during the computation. In automation testing, these unexpected situation can be like objects of application getting changed or some mathematical manipulation etc.

For handling such situation Visual Basic Script Edition (VBScript) provides us some of the methods. The details and usage of these methods are as follows:

On error resume next

This statement specifies that when any run time error occurs at particular line in script the control goes to the next line following the statement where the error as occurred.

For example: We are performing a division by zero, and if such situation occurs we dont want script to be interrupted. So we will be adding “On error resume next” statement at the top of the script.

On error resume next
Division=100/0
If Div=0 then
Msgbox “Pass”
Else
Msgbox “Fail”
End if

On error go to 0

Disables any enabled error handler and reset it to nothing

Err object

Err object is the intrinsic object with global scope means there is no need  to create the instance of it for accessing the various methods of  it.The details of all the methods of err object can be find in the below table:

Err Properties Details
Number Returns the integer value telling the type of   the error occurred
Description Gives the reason for the occurrence of the   error
Source
HelpFile
HelpContext
Err Methos Details
Clear Helps to reset the error handler to nothing   once the error has been handled.
Raise

Lets take the example of division by zero again.

'Call  the division function
call division
Function division()
on error resume next
'divide by zero
z=100/0
' Report the  error occured. You can see the error number and description in msgbox
If Err.number <> 0 then
Msgbox “Error Number” + Err.Number
Msgbox “Error Description” + Err.Description
'disables error handling
on error goto 0
End if
End function

In Visual Basic, we have two more methods available for error handling

On Error Goto Line – Moves the control to a particular line number.

On Error Goto Label – Moves the control to  a particular section of code which is defined in a label.

These two methods are not available in VBScript.

 

You may be interested

Setting up Web Service Automation Project
Katalon Studio
244 views
Katalon Studio
244 views

Setting up Web Service Automation Project

Saket - Oct 24, 2017

Web services are specific services that can be published and called over the Internet by client applications. Katalon Studio supports functional testing of web services. This topic…

Setting up Mobile Automation Project in MacOS
Katalon Studio
242 views1
Katalon Studio
242 views1

Setting up Mobile Automation Project in MacOS

Saket - Oct 09, 2017

Using Katalon Studio, mobile tester can design automation test for both Android and iOS to run on physical devices, cloud services and emulators. This tutorial explains how…

UFT Jenkins Integration
Unified Functional Testing
801 views
Unified Functional Testing
801 views

UFT Jenkins Integration

Saket - Oct 03, 2017

In our earlier post, we got to know the easy integration of UFT with GIT. This post focuses on integration of UFT and Jenkins. I have also…

Most from this category

Join The Growing Group of 15000+ Test Automation Engineers

Signup for our newsletter and get access to free downloads, as well as tips, tricks and techniques and various test automation resources.
Name
Email Address
Secure and Spam free...