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?
You better use the unhandled exception handler:
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CatchUnhandledException);
More information on the MSDN:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With