0 Shares 1214 Views 3 Comments

Error Handling in VBScript

Mar 31, 2013
1214 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

Setting up Mobile Automation Project in Windows
Katalon Studio
Katalon Studio

Setting up Mobile Automation Project in Windows

Saket - Sep 20, 2017

This tutorial explains how to setup a mobile automation project and test a mobile app using Katalon Studio on Windows. This tutorial assumes that you are familiar…

Katalon Studio GUI Overview
Katalon Studio
147 views2
Katalon Studio
147 views2

Katalon Studio GUI Overview

Saket - Sep 14, 2017

GUI Overview After installing and setting up Katalon Studio for your automated test, you must understand the GUI. In this post we will walk you through the…

LeanFT Tutorial #4: Application Model Overview
125 views1
125 views1

LeanFT Tutorial #4: Application Model Overview

Saket - Sep 10, 2017

In this post we are going to focus on Application Model in LeanFT. Refer our earlier posts on LeanFT Getting Ready with LeanFT Browser Extensions and Settings…

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...