In a C# windows application I have written code to display all exceptions. I tried the code below. When running in trace mode (pressing F5) it worked (I have written my UI event functions which has created the exceptions). But when I run the standalone exe it does not catch the exception. Instead it is displayed as an unhandled exception.
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.StackTrace);
}
}
Does anybody know about it?