Unhandled Exceptions

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

Guest

If MainForm is my entry point for my C# WinForms application, and I have
implemented a try/catch block like the following, how is it that my
application can still generate unhandled exceptions? (Message: An unhandled
exception has occurred in your application)

public class MainForm : System.Windows.Forms.Form
{
static void Main(string[] args)
{
try
{
MainForm mainForm = new MainForm();
Application.Run(mainForm);
}
catch (Exception)
{
}
}
}

Thank you very much for your consideration.
Joe
 
You want to use these instead. Put these in the Main method before
Application.Run().

Application.ThreadException+=new
System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

AppDomain.CurrentDomain.UnhandledException+=new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

HTH

Simon
 
Back
Top