private void LogUnhandledException(Exception exception, string source) { string message = $"! Unhandled exception ({source})"; Logger.Error(message); Logger.Error(exception); if (!hasShownErrorWindow) { hasShownErrorWindow = true; UnhandledErrorWindow.Show(exception); } }
private static void DispatcherUnhandledExceptionHandler(object sender, DispatcherUnhandledExceptionEventArgs e) { e.Handled = true; // ignore datagrid clipboard copy error (content is copied sucessfully anyway): // http://stackoverflow.com/questions/12769264/openclipboard-failed-when-copy-pasting-data-from-wpf-datagrid var comException = e.Exception as System.Runtime.InteropServices.COMException; if (comException != null && comException.ErrorCode == -2147221040) { return; } UnhandledErrorWindow.Open(e.Exception); }
void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { Console.WriteLine(e.Exception.ToString()); UnhandledErrorWindow uew = new UnhandledErrorWindow(e.Exception); if (uew.ShowError()) { try { as_autotyper.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Application.Current.Shutdown(); } e.Handled = true; }
private void ExportToCsv() { var dialog = new SaveFileDialog { RestoreDirectory = true, OverwritePrompt = true, FileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm"), DefaultExt = ".csv", Filter = "Comma-separated files (.csv)|*.csv" }; // Operation canceled. if (dialog.ShowDialog().GetValueOrDefault() == false) { return; } // Convert data to CSV and store them to the clipboard. UIHelper.CopyToClipboard(BookDataGrid); // Get the CSV data from the clipboard... var data = Clipboard.GetData(DataFormats.CommaSeparatedValue); try { using (var outfile = new StreamWriter(dialog.FileName)) { // ... and write the to the file. outfile.Write(data.ToString()); } } catch (Exception ex) { UnhandledErrorWindow.Open(ex); } }