I’m trying to find a way to create a nice windows form that will pop up when I encounter an unhandled exception. I currently have:
// Add the event handler for handling UI thread exceptions
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException );
// Add the event handler for handling non-UI thread exceptions
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
static void CurrentDomain_UnhandledException( object sender, UnhandledExceptionEventArgs e )
{
MessageBox.Show( e.ToString( ), "Unhandled Non-UI Thread Exception" );
}
static void Application_ThreadException( object sender, ThreadExceptionEventArgs e )
{
MessageBox.Show( e.ToString( ), "Unhandled UI Thread Exception" );
}
But what I’m looking for is to, in the threadexception methods, pop up a windows form with information about the error, and a continue/quit/restart whatever. This sounds very similar to something that, through gooogling, looks like its built in for certain cases, but is it possible to create some sort of modifiable / custom one that I can call?
Sorry, I unintentionally pasted the wrong part of code. I am currently using a message box, but want a somewhat more beefed out one with some functional buttons.
Thanks a bunch.
Sure, just create any old form, and display it using
ShowDialogat that point. You can put whatever you want on it. You could then put various buttons on it for “continue”, “restart”, “quit”, etc. You can then inspect a property of the form afterShowDialogreturns to determine what to do, based on the button clicked.