Error handling in UFT – Part 1

It is very common to get error while writing some program. But there should be a proper way to handle the errors, capture them and report them. Before jumping to error handling,let’s understand what type of errors UFT throwes. There are 2 types of errors.

1. Syntax error
2. Run time error

Syntax Error: These errors occur when there is some typos in the program like you didn’t close the bracket,there is a dot in variable name etc.UFT will show you these error in error pane at compile time or while saving the script. It will not let you proceed unless until you correct those errors.
You can also check that syntax of the program is correct or not by pressing ‘Ctrl+F7’.
Error

 

Run Time Errors: These are the errors which are evaluated during execution. It might occur due to the following reasons:

1. Trying to read the array index which is greater than size of array i.e. Array Index out of bounds.
2. Reading data from the file which is not available i.e. File not found.
3. Perform operation on the object which is not available i.e. Object not found
4. Perform incorrect arithmetic operation i.e. Dividing a number by Zero.

Handling run time errors:
There are several ways to handle the errors.

1. Handling with test settings: We can instruct UFT to take a predefined action when error occurs. We can access those settings by going to the path ‘File –> Settings–>Run(Tab)’.
You will see a dropdown ‘When error occurs during run session’. Choose a appropriate option as per the need.

Errorsettings

2. Using On Error Resume Next: 

  • On Error Resume Next – instructs UFT not to throw the error message box if any error occurs. Instead, It will move to the next line of code. It totally depends on the user’need, when he/she wants to bypass the errors.
  • On Error Go To 0 – will disable the error handling activated by On Error Resume Next.
Dim a,b
On Error Resume Next

a = 10
b = a/0
msgbox b  ' This step will show a blank message box but will not throw any error 

On Error Goto 0
a = 10
b = a/0  ' Error handling is disabled. So, it shows 'Devision by zero' error
msgbox b

3. Using Err object: This err object is in-built feature of Vbscript which will capture the error number and description of error. It will be helpful in debugging the code and can be useful for reporting as well.

  • Err.Number: Captures the Error number.
  • Err.Description: Captures the error description.
Dim a,b
On Error Resume Next

a = 10
b = a/0
msgbox err.number  ' Will give the error number 11
msgbox err.description ' Will give the description 'Devision by zero'

If at any point of time, we feel to stop the execution and exit the Test or Action. We have the following commands to do that.

ExitTest Exits from the entire Test. Nothing will run after this.
ExitAction Exits the current action.
ExitActionIteration Exits the current iteration of the action.
ExitTestIteration Exits the current iteration of the UFT test and moved to the next iteration.
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

1 Response

  1. Great article! Thanks a lot. It is nice experience to read this article on Error handling in UFT. The way you presented each point was very clear and helped me to understand it quickly. The article was very useful and informative. Keep sharing more such informative articles!