www.bitwix.com

Bitwix


Software

Snippets

Errors Caught In Program.cs

I've used this code to catch exceptions in Windows Applications. I checked that it works in MDI forms as well as in dialog forms.
        [STAThread]
        static void Main()
        {
            Application.ThreadException += new ThreadExceptionEventHandler(MyThreadHandler);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            try
            {
                Application.Run(new Form1());
            }
            catch (Exception ex)
            {
                LogUnhandledException("Main Catch", ex);
            }
        }
        static void MyThreadHandler(object sender, ThreadExceptionEventArgs e)
        {
            Exception ex = e.Exception;
            LogUnhandledException("MyThreadHandler",ex);
        }
        static void LogUnhandledException(string title, Exception ex)
        {
            MessageBox.Show(title + "\r\n\r\n" + ex.Message, 
			"Handled in Program.cs", 
			MessageBoxButtons.OK, 	
			MessageBoxIcon.Error);
        }


Whitespace

Property Hawk

Projects

This layout has been adapted from an original design by Ruthsarian Layouts, downloaded from oswd.org