Disabling VB generated error message inUnhandledException event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have enabled the "Application Framework" and am using the
My.Application.UnhandledException Event as a global error handler. For
security reasons, I am displaying a custom message to the user when the error
occurs as to not reveal any potential internal program details. This works
fine, however, after displaying my custom message box; VB.NET (2005) is
displaying a system generated error message box titled "System Error" which
displays all the gory detail I do not want to display to the user. I have
tried using "End" or e.ExitApplication = True to force the program to end
immediately after displaying my message box; but the Framework is still
displaying an error message. I do I stop this from happening? I only want
to display my message box.
 
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.
 
I found out my problem. It turns out in the nested code I received, it is
displaying another message box. Sorry for the error.
--
Thank you.


"Jeffrey Tan[MSFT]" said:
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.
 
Glad to see your problem is resolved.

Another good way to identiy where the popup message box comes from is using
debugger. For example, the popup messagebox is a modal dialog, while the
dialog is displaying, you may use a debugger to attach this process, then
you may display the stack trace of the GUI thread. This stack trace will
reveal what module and what method/function is reponsible for the popping
message box.

The debugger you are using can be either VS2005 debugger or windbg. The key
point is that you must setup the symbol server path correct so that the
debugger can load the stack trace symbols correctly.

If you need further help, please feel free to post, 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.
 
Back
Top