Results 1 to 3 of 3

Thread: Error Handling Code not Handling Error [RESOLVED]

  1. #1

    Thread Starter
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Error Handling Code not Handling Error [RESOLVED]

    I am getting some weirdness with my error handling code and I am wondering if anyone can point out what I am doing wrong:

    VB Code:
    1. Private Sub Form_Load()
    2. On Error GoTo errhandler
    3. Dim x As Integer
    4. Dim i As Integer
    5. For i = 0 To 10
    6.     x = i / 0
    7. retry:
    8. Next
    9.  
    10.  
    11. errhandler:
    12.     MsgBox "Error"
    13.     Err.Clear
    14.     GoTo retry
    15. End Sub

    The first time it runs we see the error message box. The second time it runs, we get the Run Time Error dialog box. Am I just missing something obvious? I tried putting another on Error Goto after the retry label, but that did not work.
    Last edited by Negative0; Feb 21st, 2005 at 09:17 AM.

  2. #2

    Thread Starter
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Error Handling Code not Handling Error

    Got it, just a monday morning brainfart.

    I had to do a resume next not a goto in my error handler. The goto kept us in the scope of the error handler.

  3. #3
    New Member
    Join Date
    Nov 2003
    Location
    London UK
    Posts
    15

    Re: Error Handling Code not Handling Error

    You MUST put an "Exit Sub" between the last main code line and the errorhandler label.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width