Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to end action on error
#1
Not Solved
I have found the On Error Resume Next, which will disable those pesky popup error messages that stop automation, and even found Err.Source and Err.Description to get that information again.

My question is what do I do if I want the action to terminate in the event of any error? My tests are very dependent on everything going in order (I feel like lots of tests are like this) and I just want to get the first thing that caused the error and output that to a file, and then move on to the next action (which does not require proper execution of any previous actions).

Will just using the On Error Resume Next push it through all the way to the end of the action (since one thing fails multiple more will fail)? I don't want to deal with an array of 20 errors, as they will all be useless information. The only thing I want is the first error.

Any help would be great!
Reply
#2
Not Solved
Try using "ExitActionIteration" to exit the action.

Something like

Code:
IF Err.Number<>0 Then
ExitActionIteration
End IF


Regards,
Ankesh
Reply
#3
Not Solved
When would I put this? I want the code to exit the action as soon as it errors
Reply
#4
Not Solved
wherever u are doing the error handling/Negative handling

If you know the place where the error may occur, put this code there.

Regards,
Ankesh
Reply
#5
Not Solved
Oh will it automatically jump to the Err.XXX statement if there is an error?
Reply
#6
Not Solved
You could try this. I got it from Help in QTP 11
---
On Error Resume Next
On Error GoTo 0
---
Remarks
If you don't use an On Error Resume Next statement anywhere in your code, any run-time error that occurs can cause an error message to be displayed and code execution stopped. However, the host running the code determines the exact behavior. The host can sometimes opt to handle such errors differently. In some cases, the script debugger may be invoked at the point of the error. In still other cases, there may be no apparent indication that any error occurred because the host does not to notify the user. Again, this is purely a function of how the host handles any errors that occur.

Within any particular procedure, an error is not necessarily fatal as long as error-handling is enabled somewhere along the call stack. If local error-handling is not enabled in a procedure and an error occurs, control is passed back through the call stack until a procedure with error-handling enabled is found and the error is handled at that point. If no procedure in the call stack is found to have error-handling enabled, an error message is displayed at that point and execution stops or the host handles the error as appropriate.

On Error Resume Next causes execution to continue with the statement immediately following the statement that caused the run-time error, or with the statement immediately following the most recent call out of the procedure containing the On Error Resume Next statement. This allows execution to continue despite a run-time error. You can then build the error-handling routine inline within the procedure.

An On Error Resume Next statement becomes inactive when another procedure is called, so you should execute an On Error Resume Next statement in each called routine if you want inline error handling within that routine. When a procedure is exited, the error-handling capability reverts to whatever error-handling was in place before entering the exited procedure.

Use On Error GoTo 0 to disable error handling if you have previously enabled it using On Error Resume Next.

The following example illustrates use of the On Error Resume Next statement.

On Error Resume Next
Err.Raise 6 ' Raise an overflow error.
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description
Err.Clear ' Clear the error.
Reply
#7
Not Solved
This is still not working for me. I don't want to continue on error, I want to end the current action and record the error.

Something like Try{} Catch{} in C#, where whenever an error occurs, it jumps to the Catch{} statement immediately.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Expected End statement error Lavanya N 2 5,166 07-27-2015, 01:52 PM
Last Post: Lavanya N
  closing browser at end bistritapcv 3 6,211 04-12-2013, 07:21 AM
Last Post: basanth27
  action status in QTP test - main action vanilla 1 4,616 02-12-2012, 10:59 PM
Last Post: rajpes
  How to read an * at the end of a string sqadri 2 2,581 01-06-2012, 04:01 PM
Last Post: sshukla12
  Handle start and end of tests fafanoulele 0 2,454 09-14-2011, 03:04 PM
Last Post: fafanoulele

Forum Jump:


Users browsing this thread: 1 Guest(s)