Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using OnError
#1
In my serverside HandleData i've tried to set up an error handling system. For every packet being recieved it sets CurrRunning to the packet name. Now what i want is for when it finds an error, to write it in the log. I'm not sure exactly how OnError works, just OnError Resume Next, but i'm sure someone can help me.
Reply
#2
If running the the code after the error doesnt matter, make a label at the end of the sub e.g 'ErrorHandler:' ' HandleError:' then put 'OnError GoTo ErrorHandler' or what ever you called the lebel

Btw, make sure you put exit sub or exit function before the lebel, otherwise if the code allows, it will run the error handler no matter what
Reply
#3
Code:
Sub HandleData(Index As Long, Data As String)
On Error GoTo Hell

      codecodecodecode

Exit Sub 'stupid mis
Hell:
     log code
End Sub

visual representation of what funky said.

Or soemthing like this:
Code:
Sub HandleData(Index As Long, Data As String)
On Error Resume Next

     code code code code

     If Err.Number  0 Then 'can also amke thsi so it does specific things for each error.
          log code
          Err.Clear
     End If
End Sub

that will continue through the code and post the error at the end, incase things still need to be ran further on.
Reply
#4
Quote:Sub Handledata
On error got Hell

......
exit sub
Hell:
Call errorHandler(err)
End sub
Reply
#5
Also keep in mind, On Error GoTo 0, is useful for stopping all error handling routines in the current procedure.
Reply
#6
Thanks alot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)