automationScript

VBScript examples for error handling

Error handling in UFT automation scripts is very important like any other language. We have some very common vbscript examples to demonstrate it. To show the use of different error handling statements in vbscript, we will use a function which divides an integer by zero (code given below) and produces "Division by zero error". Then we will use each error handling statements using vbscript
Division by zero error

On Error Resume Next statement enables the Error handling in the code. If there is error in the code On error Resume Next  ignores it and continues execution with next line of code. In the below example code, division by zero statement produces Division by zero error but it is ignored and next line is executed.

Error handling example

On error resume next output

On Error Go to 0

On error got to 0 statement disables error handling which we had enabled in our script by using On Error resume Next.  In the below example, please see how division by zero statement throws the Division by zero error again after disabling the error handling by using On error goto 0

Error handling example

Output 1
Output 2

err.number and err.description

Provides the error number and the description of the error

Error handling example

Subscribe for updates