Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error on On Error routine
#1
Solved: 10 Years, 7 Months, 3 Weeks ago
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
Solved: 10 Years, 7 Months, 3 Weeks ago
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
Solved: 10 Years, 7 Months, 3 Weeks ago
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 1,607 02-08-2019, 02:12 AM
Last Post: Ankur
  Error Recovery Scenario vamshiram 6 6,987 08-04-2017, 07:27 PM
Last Post: sucheta
  "Action was not found" error. What to do? ttralor 2 5,789 05-04-2017, 03:54 PM
Last Post: Ankur
  Not getting error pop up when replaying through batch amit25007 0 1,292 02-14-2017, 04:01 PM
Last Post: amit25007
  "Continue to this website (not recommended)." Error we are getting kotaramamohana 7 27,928 07-21-2016, 09:55 PM
Last Post: Ranjith Nair

Forum Jump:


Users browsing this thread: 1 Guest(s)