I want my exe to just close if any unhandle exception occurs. I have tried How can I make something that catches all 'unhandled' exceptions in a WinForms application? and also Terminate application after unhandled exception and several other posts i found in stackoverflow> But to no effect i could close the programme without showing the messagebox "Unhandled exception has occured in your application. If you click continue, the application will ignore this error and attempt to continue If you click quit ,the application will close immediately".
I want to quit the application but i dont want this message to be shown. Help is much appreciated.
The code:
[STAThread]
static void Main()
{
// Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static void MyHandler(object sender, UnhandledExceptionEventArgs e)
{
Exception exception = e.ExceptionObject as Exception;
System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess();
Application.Exit();
proc.Kill();
}
on getting exception it shows this messagebox. Cant really add it as i dont have reputation point. Jus now opened the account.
I dont want this message box to be shown and dont want to click the quit button to quit the program. Just want to quit on getting any unhandled exception.