0 Shares 4743 Views 3 Comments

Error Handling in VBScript

Mar 31, 2013
4743 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
If Div=0 then
Msgbox “Pass”
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
Err Methos Details
Clear Helps to reset the error handler to nothing   once the error has been handled.

Lets take the example of division by zero again.

'Call  the division function
call division
Function division()
on error resume next
'divide by zero
' 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

UFT Patch Updates – UFT 14.03
Unified Functional Testing
1436 views1
Unified Functional Testing
1436 views1

UFT Patch Updates – UFT 14.03

Saket - Mar 11, 2018

Post the launch of UFT 14.0, there are three patch updates has been released including a number of features and enhancement. Recently Micro Focus unveiled third patch…

Setting up Web Service Automation Project
Katalon Studio
Katalon Studio

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
1081 views1
Katalon Studio
1081 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…

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.
Email Address
Secure and Spam free...