A1VBCode Forums

HELP!


http://www.a1vbcode.com/vbforums/Topic13618.aspx

By Michael_qq - 8/15/2005

Hi, I got a code which has a lot of bugs from others. I try to debug it.
I need somebody teach me on how to use Err.Raise method.

The original code has the following structure:

private sub main()
       ::::::
       funct1()
       ::::::
end sub

public sub funct1()
       ::::
    on error goto err_hdl01
       ::::
       sub_routine3()
       ::::
       exit sub

err_hdl01:
     err_raise()
     exit sub
end sub


private sub err_raise()
       err.number = 12345
       err.description = "abcdefg"
       err.source = "xyz"
       err.raise err.number, err.source, err.description
end sub

My question is:
if Sub_routine3 returns an error, funct1 will goto err_hdl01, then it will call err_raise() which will raise another error. where does the code return to?

if Sub_routine3 returns an error, will this code fall in a died loop?

Thank you for your advice in advance.
By jviper - 8/23/2005

The error trapping works like this...

Private Sub SubRoutine

On Error Goto Label

  Do Do

  Do

  Do

  Doh!

On Error Goto 0

Exit Sub ' Ok, we've done our job here, let's get out

Label:

  Doh: There was an Error!!!

  Your in trouble, you have the right to remain silent, anything you say can and will be used agaist you the court of law........ blah, blah, blah, now do somthing about it!

   'Show a message box, or somthing, anything but what caused the error.........

   MsgBox "Error!!!!!!","Hey, dummy.......you can't to that"

End Sub

Now what will happen is, if an error occurs between On Error Goto Label, and On Error Goto 0, the the program will immedietely jump to label. Once it makes it past The On Error Goto 0, now if an error occurs, execution of the program will stop, and you will be promped with the error.