Error Handling in UFT/QTP

qtp error handling best practices
error handling in qtp guru99
general run error in uft
on error resume next
synchronization in uft
webedit properties in qtp
descriptive programming in qtp interview questions
uft interview questions

I've a framework where the methods are called inside an action from Function Libraries. I'm trying to do error handling to avoid errors thrown by code written inside the function Libraries.

Below is my action code:

on error resume next
call TestMe()
if err.number Then: msgbox err.description
on error goto 0

And here is the function inside function library:

Function TestMe()
   x = 1/0
End Function

When I execute my test, on error resume next doesn't seems to be working as I get an error pop-up for division by zero inside the function TestMe().

How can I get these error handled without moving the code?

Surprisingly with all the time using QTP/UFT never came up against such case. Was quite intriguing as well. I Found out (or so it seems at first glance) that the scope of on error resume next is limited to its level (Library/Action) and couldn't be carried over to either.

You might wanna try something like:

Action Code:

Call Test3()

Function Library:

Function Test1()
      x = 1/0
End Function

Function Test2()
   Call Test1()
   MsgBox "Test2"
End Function

Function Test3()
   On Error Resume next
   Call Test2()
   MsgBox err.Description
End Function

The execution using this statement continues until it finds a handler. So you may set up a condition where ever you deem fit.

Another alternative is to use a flag (could be an environment variable) like

Environment("Flag") = True

Whose condition can be checked directly in action code

Hope this helps. I'll still try to dig up more about this

QTP - Error Handling, Surprisingly with all the time using QTP/UFT never came up against such case. Was quite intriguing as well. I Found out (or so it seems at first  Flag is nothing but an environment variable. You can set the environment variable as true (while you want to begin execution) and when some condition fails (which can be either in library or action) you can set the environment variable as False, now you need to add a condition under each function you are calling to check for the flag ( so each function is called only if the flag is True) this

Check the below article. This is explaining the same issue in detail

https://sumeetkushwah.com/2014/08/12/implementing-try-catch-functionality-in-qtpuft/

Error Handling in UFT/QTP, UFT/QTP · 1 Before jumping to error handling,let's understand what type of errors UFT throwes. There are 2 types of errors. UFT will show you these error in error pane at compile time or while saving the script. It will not let  How to Pass Excel Assessment Test For Job Applications - Step by Step Tutorial with XLSX work files - Duration: 19:48. Online Training for Everyone 58,530 views

on error resume next

call TestMe()

on error goto 0

if err.number Then: msgbox err.description

Function TestMe()

   x = 1/0

End Function

Error handling in UFT - Part 1, VBScript basically supports 2 main methods to handle errors in the scripts. They are as follows: #1) On Error Resume Next. Most of us must have  Hi All, I want to know the situation. Suppose when we navigae to different pages in web application, and that pages use SSL at that time Window pop ups stating sometihing like ' The page you are movin

VBScript Error Handling: VBScript On Error, On Error GoTo 0, On , Hello friends, In this post we will discuss about how we can generate the same try catch behavior in VBS/UFT, which comes inbuilt in Java or . In VBScript there is no facility to call a statement/function on error. But you can use err object to perform condition based error handling. On Error Resume Next, Go to 0 and Err objects will work for VBScript as well as for QTP Objects. Err Object: This object captures the information about runtime errors. Using this you can always get the last error details.

UFT Tutorial 36: Error Handling in UFT / QTP, Qtp / UFT withVbscript, 26th March 2020, 9.00 PM IST to 10:30 PM IST, 30 Days, WeekDays, Online Error Handling and Recovery Scenarios in QTP - Part-2 But Recovery Scenarios will not handle VBScript Errors. 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.

Difference between error handling and exception , 1.4 How to handle VBScript Errors in UFT or VBScript Editor? In UFT/QTP we tend to put error handling code in respective functions, which  Error Handling in QTP Error and Exception Handling Unexpected events, errors, and application crashes during a run session can disrupt the run session and distort results.

Comments
  • Why would you not expect an error pop-up? That's how you have it coded. You return from the call and say "if I have an error show a message".
  • This statement works fine! Double-check your code!
  • @BrianMStafford -> Error message is thrown inside the function TestMe()
  • @GTAVLover Code is similar, It's just error thrown from the function library is not being handled by the on error resume next inside the Action.
  • @yudi2312 Then add this statement inside the function also! :-)
  • I was thinking of creating a method to execute other methods to make sure that all errors are rescued. And I'm not clear about the alternative approach by using a flag. Can you thrown some more light on this?
  • I dont know how your code is and so it is difficult to suggest on it. but if your goal is to not use on error statement multiple times then you can do so using the above answer. Mind you it will work only at a level i.e. library file - in the above example you may use on error statement in the Test1() as well and handle it in Test3().
  • Flag is nothing but an environment variable. You can set the environment variable as true (while you want to begin execution) and when some condition fails (which can be either in library or action) you can set the environment variable as False, now you need to add a condition under each function you are calling to check for the flag ( so each function is called only if the flag is True) this way if any one function has failed you would come out of it. This explanation is just elementary, you would need script it according to your need.