Unhandled Exception in Winforms Application

I have a simple WinForms application that is used to enter test cases. Since I upgraded this application to .NET 4.0 and added a new tab to the tab control for XML validation using the XSD scheme, the application accidentally crashed. I could not reproduce the exception.

The error my QA guy is getting is a generic Windows message:

TestCaseViewer has encountered a problem and needs to close. We regret the inconvenience.

To try to get to the real error, I added the following code at the beginning of the main program method:

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.ThreadException += Application_ThreadException; 

Event handlers are as follows:

  static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { try { MessageBox.Show(e.Exception.ToString(), @"Thread Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { Application.Exit(); } } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { try { var ex = (Exception)e.ExceptionObject; MessageBox.Show(ex.ToString(), @"Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { Application.Exit(); } } 

Unfortunately, this did not help, and everything that happens continues to work in such a way as to generate an unhandled error that bubbles up to the OS.

Can anyone give me any other ideas on throwing this exception?

+6
exception winforms unhandled
Feb 19 '11 at 5:23
source share
2 answers

Try adding the following to your app.config

 <runtime> <!-- the following setting prevents the host from closing when an unhandled exception is thrown --> <legacyUnhandledExceptionPolicy enabled="1" /> </runtime> 
+9
Mar 11 '13 at 21:16
source share

If you use Visual Studio, you can set it to break in all unhandled exceptions, and even at any time when an exception is thrown, regardless of whether it is handled by your code.

To do this, select Exceptions in the Debug menu. A dialog box appears that looks like this:

Visual Studio Exceptions dialog

If you really want to be serious, try checking all the fields. Then, learn from your QA guy what exactly is done to trigger the exception, and accurately reproduce these actions while working as part of the debugger in the development environment. Whenever an exception is thrown, Visual Studio is interrupted and you will see a line with a code violation along with a full stack trace.

+2
Feb 19 '11 at 6:20
source share



All Articles