Application.SetUnhandledExceptionMode()

  • Thread starter Thread starter Grant Morgan
  • Start date Start date
G

Grant Morgan

Hi

I'm relatively competent at windows forms programming in net 2.0 (VS 2005),
however, I've never really gotten my hands dirty with exception handling
until now...

My application is using a startup form (not a sub main) for a windows forms
project, with application framework enabled.

I have found the MyApplication_UnhandledException event, and have used this
to report on any unhandled exceptions. However, it only works if I run the
application in Release mode (ie. not debug mode) and without the VSHost
process (ie. running it outside of VS 2005).

I've been told the way around this is to set the
Application.SetUnhandledExceptionMode - can I only do this from a Sub Main
startup, or can I somehow use the MyApplication_Startup event?

Sorry if my description is all over the place - my brain is a bit "googled"
after reading up on exception handling....

Cheers
Grant
 
Hi Grant,

Thanks for your support for Microsoft and VS 2005.

In VB.NET, when an applicatin encounters an unhandled exception, it raises
the UnhandledException event. However, the Visual Basic compiler prevents
applications that are built for debugging from raising this event, to allow
a debugger to handle the unhandled exceptions. This means that if you are
testing your application by running it under the VS IDE debugger, your
UnhandledException event handler will not be called.

This behavior has nothing to do with the
Application.SetUnhandledExceptionMode method.

What's more, Application.SetUnhandledExceptionMode method must be called
before you instantiate the main form of your application. That's to say,
if you are going to call this method, you must call it in a Sub Main
startup and before the Applicaiton.Run code(you couldn't call this method
in the Application's Startup event handler). However, it means that you
have to disable application framework and select Sub Main as the Startup
object, which conflicts with the Visual Basic Application Model that
UnhandledException event requires.

Hope this helps.
If you have any concerns, please feel free to let me know.


Sincerely,
Linda Liu
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.
 
Hi Linda Liu,

I use a C#.Net windows application. I have set the setunhandledexception mode to catch exception and subscribed to ThreadException and Unhandled exception. But still it could not able to catch an exception explicitly thrown from a non-UI thread. What i have to do in my application to catch exception thrown from a non-main,non-UI thread. Thanks in advance.

Thanks & Regards
Anand
 
Back
Top