Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 ?
 
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
 
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 6-Jan-13 2:03am
Edited 6-Jan-13 3:29am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
Wietze Bron at 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ő at 6-Jan-13 8:22am
   
I don't know what you have in your code, but I am getting the exception.
Wietze Bron at 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 at 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ő at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,651
1 Sergey Alexandrovich Kryukov 6,400
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,542


Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 6 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100