Unhandled Exceptions

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
 
S

Simon Tamman {Uchiha Jax}

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top