Top-level Exception Handling – Code Listing 4

        static void Main()
         {
             Application.ThreadException += new ThreadExceptionEventHandler(new ThreadExceptionHandler().ApplicationThreadException);
             MainForm mainForm = null;
             try
             {
                 SplashScreen splash = new SplashScreen();
                 splash.Show();
                 DoLongRunningSetUpStuff();
  
                 // Instantiate and initialize our main form here - we have exception handling in place
                 mainForm = new MainForm();
                 mainForm.Initialize();
  
                 splash.Close();
             }
             catch (Exception e)
             {
                 // You probably want something a little more sophisticated than this
                 MessageBox.Show(e.Message"An exception occurred:"MessageBoxButtons.OKMessageBoxIcon.Error);
                 System.Environment.Exit(0);
             }
  
             Application.Run(mainForm);
         }
Advertisements

2 thoughts on “Top-level Exception Handling – Code Listing 4

  1. Okay if new ThreadExceptionHandler() is your own method for dealing with the exception, why does it not tie into the example? I mean what would I put in place of that. It does not compile on my system because my ide does not recognize new ThreadExceptionHandler()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s