Friday, June 29, 2012

CLR Errors - crashing without actually running

are usually caused by invalid references

to a windows program you can add the following for error handling in program.cs

  [STAThread]
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException +=
            new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //CheckForShortcut();
            Application.Run(new Invoice());
        }

        static void CurrentDomain_UnhandledException
  (object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                Exception ex = (Exception)e.ExceptionObject;

                MessageBox.Show(ex.Message + ex.StackTrace,
                      "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            finally
            {
                Application.Exit();
            }
        }

No comments:

Post a Comment