public static void DisplayException(Exception ex) { if (!Application.Current.Dispatcher.CheckAccess()) { Application.Current.Dispatcher.Invoke(((Action)(() => DisplayException(ex)))); return; } // Record this exception at server so that we know about it { string message = ex.Message; string stack_trace = ex.StackTrace; int MAX_CHARS = 512; if (null != stack_trace && stack_trace.Length > MAX_CHARS) { stack_trace = stack_trace.Substring(0, MAX_CHARS - 3) + "..."; } FeatureTrackingManager.Instance.UseFeature( Features.Exception, "Ver", ClientVersion.CurrentVersion, "Message", message, "Stack", stack_trace ); } string useful_text_heading = "Something unexpected has happened, but it's okay."; string useful_text_subheading = "You can continue working, but we would appreciate it if you would send us some feedback on what you were doing when this happened."; // should we display a better message // TODO: make this a bit neater if (ex != null) { // very broad descriptions based on the exceptions we caught if (ex.GetType() == typeof(PathTooLongException)) { useful_text_heading = "Maximum path length exceeded"; useful_text_subheading = "A very long path was entered (more than 260 characters). If you were importing documents, please move the documents into a folder with a shorter path before retrying the import."; } } // Check if this is an exception we know about and want to be a little more friendly UsefulTextException ute = ex as UsefulTextException; if (null != ute) { useful_text_heading = ute.header; useful_text_subheading = ute.body; } Display("Unexpected problem in Qiqqa!", useful_text_heading, useful_text_subheading, null, true, false, ex); }
public static void DisplayException(Exception ex) { // When we're looking at an OutOfMem exception, there's nothing we can do but abort everything! if (ex is System.OutOfMemoryException) { throw new OutOfMemoryException("Out of memory", ex); } // the garbage collection is not crucial for the functioning of the dialog itself, hence dump it into a worker thread. SafeThreadPool.QueueUserWorkItem(o => { // Collect all generations of memory. GC.WaitForPendingFinalizers(); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true); }); string useful_text_heading = "Something unexpected has happened, but it's okay. " + ex.Message; string useful_text_subheading = "You can continue working, but we would appreciate it if you would send us some feedback on what you were doing when this happened."; // should we display a better message // TODO: make this a bit neater if (ex != null) { // very broad descriptions based on the exceptions we caught if (ex.GetType() == typeof(PathTooLongException)) { useful_text_heading = "Maximum path length exceeded"; useful_text_subheading = "A very long path was entered (more than 260 characters). If you were importing documents, please move the documents into a folder with a shorter path before retrying the import."; } } // Check if this is an exception we know about and want to be a little more friendly UsefulTextException ute = ex as UsefulTextException; if (null != ute) { useful_text_heading = ute.header; useful_text_subheading = ute.body; } Logging.Error(ex, "Unhandled Exception Handler: {0} - {1}", useful_text_heading, useful_text_subheading); // make sure we're not in the process of shutting down Qiqqa for then the next code chunk will cause a (recursive) CRASH: if (ShutdownableManager.Instance.IsShuttingDown) { Logging.Error(ex, "Unhandled Exception Handler: detected Qiqqa shutting down."); } else { // Record this exception at server so that we know about it { string message = ex.Message; string stack_trace = ex.StackTrace; int MAX_CHARS = 512; if (null != stack_trace && stack_trace.Length > MAX_CHARS) { stack_trace = stack_trace.Substring(0, MAX_CHARS - 3) + "..."; } FeatureTrackingManager.Instance.UseFeature( Features.Exception, "Ver", ClientVersion.CurrentVersion, "Message", message, "Stack", stack_trace ); } Display("Unexpected problem in Qiqqa!", useful_text_heading, useful_text_subheading, null, true, false, ex); } }