Error Handling in QTP? - TestingQ.com

-->Exclusive Portal for Testing Jobs

Error Handling in QTP?

we can Handle Erors in 2 ways by using 
  1. Recovery Scenarios. 
  2. Using “On Error” statement 
In Recovery scenario Manager you have to define.
1. Triggered Events. 
2. Recovery steps. 
3. Post Recovery Test-Run. 


At Script Level you can use the On Error Resume Next statement. 
Following code throws an Exception at Line 6, and the execution cannot proceed further.
msgbox "hello"
call funcOne
msgbox "after function call"

function funcOne()
msgbox 1/0
end function
Here the output is "hello", the script never reaches to the second output statement

To proceed further after the exception occured, use "On Error Resume Next" statement, which just ignores the Exception and proceeds.
msgbox "hello"
call funcOne
msgbox "after function call"

function funcOne()
On Error Resume Next
msgbox 1/0
end function
Here the output contains both the messages

To customize the error message displayed, use the Err Object
msgbox "hello"
call funcOne
msgbox "after function call"

function funcOne()
On Error Resume Next
msgbox 1/0
msgbox "Error Message: "&Err.Description&" and Error code: "&Err.Number
end function
Here the output is 3 msgs, including the Error description.

You can also clear the Error object using Err.clear().
To receive daily posted JOBS & Interview Questions
Just enter your email address below and click 'Submit'
Enter your email address:

Make sure to activate your subscription by clicking on the activation link sent to your email