/// ------------------------------------------------------------------------------------ /// <summary> /// Set exception handler. Needs to be done before we create splash screen (don't /// understand why, but otherwise some exceptions don't get caught). /// </summary> /// ------------------------------------------------------------------------------------ public FatalExceptionHandler() { // We need to create a WinFormsExceptionHandler so that if we ever need to use the fallback // SIL.Reporting.ErrorReport system it has a valid ControlOnUIThread prop. // Creating the object is enough to solve this problem. We keep a reference so it gets collected // when we go away. // Passing false keeps the WinForms handler from responding to exceptions, so we don't get two // handlers vying for who gets to report an error. _fallbackHandler = new WinFormsExceptionHandler(false); UseFallback = true; // We need to create a control on the UI thread so that we have a control that we // can use to invoke the error reporting dialog on the correct thread. ControlOnUIThread = new Control(); ControlOnUIThread.CreateControl(); // Using Application.ThreadException rather than // AppDomain.CurrentDomain.UnhandledException has the advantage that the // program doesn't necessarily end - we can ignore the exception and continue. Application.ThreadException += HandleTopLevelError; // We also want to catch the UnhandledExceptions for all the cases that // ThreadException don't catch, e.g. in the startup. AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException; }