Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error on On Error routine
#1
Solved: 10 Years, 8 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


Messages In This Thread
Error on On Error routine - by upadhyay40 - 12-23-2009, 07:40 PM
RE: Error on On Error routine - by Saket - 12-24-2009, 10:56 AM
RE: Error on On Error routine - by jsknight1969 - 12-29-2009, 03:18 AM

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

Forum Jump:


Users browsing this thread: 1 Guest(s)