public WmErrorGer(WmErrorMsg errorMsg) { ErrorMsg = errorMsg; }
/// <summary> /// Display an error message to the user and exit the application if /// required. /// </summary> public static void HandleError(String errorMessage, bool fatalFlag) { string msg = "An error has been detected." + Environment.NewLine + Environment.NewLine + errorMessage + Environment.NewLine + Environment.NewLine; if (fatalFlag) { msg += "Please restart your " + KwmStrings.Kwm; } else { msg += "Please contact your technical support for further information."; } // Transient error. Queue the message to be displayed. if (!fatalFlag) { WmErrorMsg em = new WmErrorMsg(); em.Ex = new Exception(errorMessage); WmErrorGer ger = new WmErrorGer(em); ger.Queue(); return; } // The .Net framework is critically brain damaged when it comes to // handling fatal errors. There are basically two choices: exit // the process right away or try to get the application to display // the error and quit. // // The former choice is sane; there is no risk of further data // corruption if the process exits right away. The lack of any // error message is problematic however. We work around this by // spawning an external program, if possible, to report the error // before exiting the process. // // The second choice cannot be done sanely. If a MessageBox() // call is made immediately when the error is detected, then // the UI will be reentered and the damage may spread further. // Typically this causes multiple fatal error messages to // appear. After some investigation, I believe this is impossible // to prevent. The best available thing is ThreadAbortException, // which has weird semantics and is considered deprecated and // doesn't do the right thing in worker threads. // Exit right away. if (!FatalErrorMsgOKFlag || m_fatalErrorCaughtFlag) Environment.Exit(1); // We have caught a fatal error. Prevent the other threads from // spawning a fatal error. There is an inherent race condition // here which is best left alone; mutexes have no business here. m_fatalErrorCaughtFlag = true; // Bad error handling. MessageBox.Show(errorMessage); // Get out. Environment.Exit(1); }