AppDomain Question [modified]
-
I have an MDI form where I set the following Handler in Form_Load
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException
If I throw an exception in the MDI form the exception gets handled by CurrentDomain_UnhandledException But, If I load a child form and throw an exception from the child form the excpetion does not get handled by CurrentDomain_UnhandledException So, Is the child form running in a different AppDomain then the MDI form. How can I get this to work or does this not work the way I thought it would. Here is my form load which is also in the MDI formf = New formDesignErrorsList f.Tag = formname f.Text = f.Text f.MdiParent = Me f.Show()
Thanks -- modified at 22:46 Wednesday 23rd August, 2006 -
I have an MDI form where I set the following Handler in Form_Load
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException
If I throw an exception in the MDI form the exception gets handled by CurrentDomain_UnhandledException But, If I load a child form and throw an exception from the child form the excpetion does not get handled by CurrentDomain_UnhandledException So, Is the child form running in a different AppDomain then the MDI form. How can I get this to work or does this not work the way I thought it would. Here is my form load which is also in the MDI formf = New formDesignErrorsList f.Tag = formname f.Text = f.Text f.MdiParent = Me f.Show()
Thanks -- modified at 22:46 Wednesday 23rd August, 2006mtone wrote:
Is the child form running in a different AppDomain then the MDI form.
No, it's not. It's all in the same AppDomain. What's the exception that's not getting handled?
Dave Kreskowiak Microsoft MVP - Visual Basic
-
mtone wrote:
Is the child form running in a different AppDomain then the MDI form.
No, it's not. It's all in the same AppDomain. What's the exception that's not getting handled?
Dave Kreskowiak Microsoft MVP - Visual Basic
In the Main (MDI) form My test is just trowing an new exception. Here is gets handled by CurrentDomain_UnhandledException and ultimatly ends up in The EventLog
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler Application.ThreadException, AddressOf ApplicationThreadException AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException Throw New Exception("This is a test") End Sub
If I put the sameThrow New Exception("This is a test")
in the onload event of the mdi child it does not get handled nor does it make it to the event log. If I set a break point I can see that CurrentDomain_UnhandledException is never called. Thanks Joe -
In the Main (MDI) form My test is just trowing an new exception. Here is gets handled by CurrentDomain_UnhandledException and ultimatly ends up in The EventLog
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler Application.ThreadException, AddressOf ApplicationThreadException AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException Throw New Exception("This is a test") End Sub
If I put the sameThrow New Exception("This is a test")
in the onload event of the mdi child it does not get handled nor does it make it to the event log. If I set a break point I can see that CurrentDomain_UnhandledException is never called. Thanks JoeWell, I did this and it did what was expected of it:
' Form1
Private Sub Form1_Load(blah, blah) Handles Me.Load
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledExceptionHandler
Dim c As New Form2
c.MdiParent = Me
c.Show()
End Sub
Private Sub UnhandledExceptionHandler(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
Debug.WriteLine("Unhandled Exception!!")
End Sub
' Form2
Private Sub Form2_Load(blah, blah) Handles Me.Load
Throw New Exception("Yikes!")
End SubThe exceptions don't make it to the event log because there's nothing telling the app to log them. But, the exception was caught by the UnhandledExceptionHandler.
Dave Kreskowiak Microsoft MVP - Visual Basic
-
Well, I did this and it did what was expected of it:
' Form1
Private Sub Form1_Load(blah, blah) Handles Me.Load
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledExceptionHandler
Dim c As New Form2
c.MdiParent = Me
c.Show()
End Sub
Private Sub UnhandledExceptionHandler(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
Debug.WriteLine("Unhandled Exception!!")
End Sub
' Form2
Private Sub Form2_Load(blah, blah) Handles Me.Load
Throw New Exception("Yikes!")
End SubThe exceptions don't make it to the event log because there's nothing telling the app to log them. But, the exception was caught by the UnhandledExceptionHandler.
Dave Kreskowiak Microsoft MVP - Visual Basic
Thanks Dave I have the code that writes to the event log in another function I am using the Enterprise Library to handle the event logging. Well, the event log was not the problem just a way for me to see the exception followed the proper route. I will keep looking at it, so long as I know it should work.
-
Thanks Dave I have the code that writes to the event log in another function I am using the Enterprise Library to handle the event logging. Well, the event log was not the problem just a way for me to see the exception followed the proper route. I will keep looking at it, so long as I know it should work.
In my testing, there is a problem with using the UnhandledException event. It doesn't get fired unless the code is running under the debugger! Go figure...
Dave Kreskowiak Microsoft MVP - Visual Basic