Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I call a form from another form, there are no errors caught.

In my sample code the messagebox for ready is rightfully not executed because the statement is not valid, so there should be an unhandled error message, which is not given.
What is the problem here ?

VB
Public Class Form1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Form2.Show()
        Form2.Dispose()
    End Sub
End Class


VB
Public Class Form2
    Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim i, j As Integer
        MsgBox("begin")
        j = 0
        i = 100 / j
        MsgBox("ready")
    End Sub
End Class



I have tested it on another PC with the sdame instance of VS2010. I used exactly the same code and here I don't have the problem. Could it be a central setting or something ?
Posted
Updated 6-Jan-13 3:29am
v2

Calling Show() does not make make second form modal, thus execution continues in the _Click event. And _Load method is not the first to call during form creation. This Dispose() is called before can reach your code. Try ShowDialog() and you will get your exception.
 
Share this answer
 
v2
Comments
Wietze Bron 6-Jan-13 8:16am    
I am sorry, this makes no difference. The begin messagebox was
already shown in the first place, so this has nothing to do with the code
being executed or not in the form2_load.
Zoltán Zörgő 6-Jan-13 8:22am    
I don't know what you have in your code, but I am getting the exception.
Wietze Bron 6-Jan-13 8:43am    
Hi Zoltan, thanks for your reaction.

I just used the code plain as stated above and I get no exception.
Form2 comes up whith the first messagebox and not with the second.

When I change form2 to the following I get an exception, but there should always be an unhandled exception I think.

Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim i, j As Integer
Try
MsgBox("begin")
j = 0
i = 100 / j
MsgBox("ready")
Catch ex As Exception
Call MsgBox(ex.Message)
End Try
End Sub
Wietze Bron 6-Jan-13 9:30am    
I have tested it on another PC with the sdame instance of VS2010. I used exactly the same code and here I don't have the problem. Could it be a central setting or something ?
Zoltán Zörgő 6-Jan-13 12:10pm    
Catching unhandled exceptions by the IDE is a gray area. Check this, just as a chance:
http://blogs.msdn.com/b/debugger/archive/2010/05/12/visual-studio-debugger-fails-to-catch-unhandled-exception-for-a-windows-form-or-wpf-application.aspx
I suggest try running your code outside VS. Look at the system logs too.
Thanks Zoltan, you have been very helpfull.
Your suggested link was exactly what applied to my case.
The problem exists on a 64 bit Win7 system and not on the 32 bit Win7 system, which I tried later on. The workaround in the link however, is only partly usefull.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900