Hi,
Since the My.Application.UnhandledException can only be used in VB2005
winform project, I am assuming that you are using .Net Winform.
I have created a sample "UnhandledExceptionTestVB" winform project in
VB2005. In the sample, I throw the exception in Button_Click event:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Throw New Exception("this is a test")
End Sub
Also, I handled the My.Application.UnhandledException in
ApplicationEvents.vb file below:
Namespace My
Partial Friend Class MyApplication
Private Sub MyApplication_UnhandledException(ByVal sender As
Object, ByVal e As
Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs)
Handles Me.UnhandledException
MessageBox.Show(Environment.StackTrace)
e.ExitApplication = True
End Sub
End Class
End Namespace
After dismiss the messagebox from the MyApplication_UnhandledException, my
test winform application will terminate silently without any error message
box titled with "System Error". So it seems that your application has
different behavior with my test project. Is it possible for you to create a
little sample project to help me reproduce this problem? Then it would be
more efficient for me to troubleshoot the root cause.
Additionally, can you be specific what "End" method you are calling in your
application? I can not find this method on UnhandledExceptionEventArgs
class.
Finally, here is some additional information:
My.Application.UnhandledException is actually an extra facility introduced
by VB2005, which is not available from other languages. Actually it is very
different from AppDomain.UnhandledException event.
AppDomain.UnhandledException event is a CLR notification which is called
whenever an unhandled exception is generated in the AppDomain. Note:
AppDomain.UnhandledException event is merely a notification, you can not
use AppDomain.UnhandledException to tell CLR to dismiss the exception and
continue execute. The CLR will always shutdown the AppDomain after
AppDomain.UnhandledException event.
My.Application.UnhandledException is actually more like
Application.ThreadException event in .Net Winform. Actually, this event is
called by a pre-registered Application.ThreadException handler of VB2005.
To prove this, you may examine the call stack in
My.Application.UnhandledException event handler, see below:
UnhandledExceptionTestVB.exe!UnhandledExceptionTestVB.My.MyApplication.MyApp
lication_UnhandledException Basic
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsF
ormsApplicationBase.raise_UnhandledException Basic
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsF
ormsApplicationBase.OnUnhandledException Basic
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsF
ormsApplicationBase.OnUnhandledExceptionEventAdaptor Basic
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.OnTh
readException C#
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProcException C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.On
ThreadException C#
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback C#
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.S
ystem.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoo
p C#
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunM
essageLoopInner C#
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunM
essageLoop C#
System.Windows.Forms.dll!System.Windows.Forms.Application.Run C#
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsF
ormsApplicationBase.OnRun Basic
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsF
ormsApplicationBase.DoApplicationModel Basic
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsF
ormsApplicationBase.Run Basic
As you can see, "OnThreadException" upper in the stack calls
MyApplication_UnhandledException finally.
Note: this is just more information. It still can not explain why there is
an extra "System Error" message box generated in your project. A little
sample project is still useful for me to debug the root cause. I will wait
for it.
Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.