CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  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 & bCrLf & 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
    SubErr_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
    Apr 2001
    Location
    Wisconsin, USA
    Posts
    150

    Re: Error handling problem

    Not to sound mean, but check your typing. In your form_load subroutine, you state on error goto Err_Form1_Form_Load

    , but you have the error labeled as SubErr_Form1_Form_Load

    . Making these two the same might help.


  3. #3
    Join Date
    Mar 2001
    Posts
    4

    Re: Error handling problem

    It's a typo... The code compiles and runs!



  4. #4
    Join Date
    May 2001
    Posts
    40

    Re: Error handling problem

    second pair of eyes strikes again LOL


  5. #5
    Join Date
    Jun 2001
    Posts
    2

    Re: Error handling problem

    I also have the same problem, have you find any answers ???
    if so please answer this.

    thanks


  6. #6
    Join Date
    Jan 2000
    Location
    Pennsylvania, United States
    Posts
    106

    Re: Error handling problem


    It is important to note the call stack.

    What you have may seem correct... But you have to be aware that when you propogate errors, there must be a handler ready waiting for your raise of that error.

    In your example you have a error occurring in your form_load event. It may seem that the calling routine would be receiving the error from the form. Put a break point on your array assigment in the form. Run the application. When the program stops on the break point. Select View; Call Stack from the visual IDE. A box will display showing you the call stack.

    It will show you there is a break in your call stack between the module function and the form_load event. Something like non-basic code.

    The load event does not have something to pass it's error code to. You will notice the same problem if you remove the error handler all together from the form_load event.

    Sorry... Can't explain more without looking this up again... But this should give you a start.

    -David



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