CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2001
    Posts
    4

    Error handling problem

    I have a serious problem with th error handling prcess. For a reason I can't understand, if you raise an error in a Form, this error don't go down on the calling procedure. This exemple will help you understand what I mean :



    MODULE1.MOD

    option Explicit

    Sub Main()

    on error GoTo Err_Module1_Main

    from1.Show

    Exit Sub

    Err_Module1_Main:

    MsgBox Err.Number & vbCrLf & Err.Source & vbCrLf & Err.Description

    End Sub


    FORM1.FRM

    option Explicit

    private Sub Form_Load()
    Dim intVar(2) as Integer
    on error GoTo Err_Form1_Form_Load

    intVar(-1) = 3

    Exit Sub

    Err_Form1_Form_Load:

    Err.Raise Err.Number, Err.Source, Err.Description

    End Sub





    As you can see, the entry point of my program is Sub Main(). In this procedure, I'm loading a Form called Form1. There is an intentionnal "Subscript out of range" error in the Form_Load of Form1. The "On Error" statement being in the codem the error is traped, and we end up in the "Err_Form1_Form_Load:" section. In this section, I do an "Err.Raise" which should be sent to the "Sub Main()" of MODULE1.MOD, but it dosen't.

    As far as I know, when raise errors in VB this error should go down on the calling procedure... Why isn't it doing so?

    Please help me!


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Error handling problem

    Well, you have a problem here. If you call a sub or function which raises an error (or just causes an error) the errorhandler is used. In you case, the errorhandler of the form_load. This errorhandler raises an error, resulting in the same errorhandler being raised again. Here's your first problem.

    The second problem is bigger. The error happens in the form_load event. This method is not called by the form.show method, but it just happens, it's an event, and the caller of an event is the system.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured