Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error on On Error routine
#1
Hello All,

I am trying to implement On Error Resume Next in my code but i got error on 2 line

The test run cannot continue due to a syntax error.
Syntax error
Line (1):
Code:
"On Error GoTo ErrorHandler: ' Enable error-handling routine.".

can any body please help me out to solve my problem.
My Code:
Code:
Public Sub OnErrorDemo() On Error GoTo ErrorHandler: ' Enable error-handling routine. Dim x,y,z x = 32 y = 0 z = x / y ' Creates a divide by zero error On Error GoTo 0 ' Turn off error trapping. On Error Resume Next ' Defer error trapping. z = x / y ' Creates a divide by zero error again If Err.Number = 6 Then ' Tell user what happened. Then clear the Err object. Dim Msg As String Msg = "There was an error attempting to divide by zero!" MsgBox(Msg, , "Divide by zero error") Err.Clear() ' Clear Err object fields. End If Exit Sub ' Exit to avoid handler. ErrorHandler: ' Error-handling routine. Select Case Err.Number ' Evaluate error number. Case 6 ' Divide by zero error MsgBox("You attempted to divide by zero!") ' Insert code to handle this error Case Else ' Insert code to handle other situations here... End Select Resume Next ' Resume execution at same line ' that caused the error End Sub

Thanks
Mahesh
Reply
#2
Hi Mahesh,
'On Error GoTo ErrorHandler' is not supported in QTP so you can not use the statement here.
you can use only 'on error resume next' or 'on error goto 0'
@Everyone - Please put your codes in proper tags, which makes easier to read through all the statements.
Refer Help (top right of this page)

Reply
#3
You can use the Err object in an if/case statement to handle error.

Code:
on error resume next z = 1/0 select case err.number case -21345896 'please look up the correct error number msgbox err.description & ": you divided by zero" case else msgbox err.description end select

I created a class to handle error and enhanced the class with a DLL written in .NET to store to eventlog, file, or database. You don't need .NET for file or database, I just prefer the eventlog and could write it easily in .NET. To use the class just replace the case statement with a sub call and pass the err object.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  General run error when Exist fails msacks 1 2,446 02-08-2019, 02:12 AM
Last Post: Ankur
  Error Recovery Scenario vamshiram 6 8,700 08-04-2017, 07:27 PM
Last Post: sucheta
  "Action was not found" error. What to do? ttralor 2 6,817 05-04-2017, 03:54 PM
Last Post: Ankur
  Not getting error pop up when replaying through batch amit25007 0 1,825 02-14-2017, 04:01 PM
Last Post: amit25007
  "Continue to this website (not recommended)." Error we are getting kotaramamohana 7 35,240 07-21-2016, 09:55 PM
Last Post: Ranjith Nair

Forum Jump:


Users browsing this thread: 1 Guest(s)