OpenBve.CrashHandler.CurrentDomain_UnhandledException C# (CSharp) Method

CurrentDomain_UnhandledException() static private method

Catches all unhandled exceptions within the current appdomain
static private CurrentDomain_UnhandledException ( Object sender, UnhandledExceptionEventArgs e ) : void
sender Object
e System.UnhandledExceptionEventArgs
return void
        internal static void CurrentDomain_UnhandledException(Object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                Exception ex = (Exception)e.ExceptionObject;
                if (ex is ArgumentOutOfRangeException && ex.Message == "Specified argument was out of the range of valid values.\r\nParameter name: button")
                {
                    //If a joystick with an excessive number of axis or buttons is connected, at the least show a nice error message, rather than simply dissapearing
                    MessageBox.Show("An unsupported joystick is connected: \n \n Too many buttons. \n \n Please unplug all USB joysticks & gamepads and try again.");
                    Environment.Exit(0);
                }
                if (ex is ArgumentOutOfRangeException && ex.Message == "Specified argument was out of the range of valid values.\r\nParameter name: axis")
                {
                    //If a joystick with an excessive number of axis or buttons is connected, at the least show a nice error message, rather than simply dissapearing
                    MessageBox.Show("An unsupported joystick is connected: \n \n Too many axis. \n \n Please unplug all USB joysticks & gamepads and try again.");
                    Environment.Exit(0);
                }
                MessageBox.Show("Unhandled exception:\n\n" + ex.Message);
                LogCrash(ex + Environment.StackTrace);

            }
            catch (Exception exc)
            {
                try
                {
                    MessageBox.Show("A fatal exception occured inside the UnhandledExceptionHandler: \n\n"
                        + exc.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        LogCrash(exc + Environment.StackTrace);
                }
                finally
                {
                    Environment.Exit(0);
                }
            }
        }