private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e) { Logger logger = LogManager.GetCurrentClassLogger(); var exception = e.ExceptionObject as Exception; if (exception == null) { logger.Error("Unhandled non-CLR exception occured ({0})", e.ExceptionObject); } else { logger.Error( "Domain unhandled exception of type {0} occured ({1})", e.GetType().Name, e.ExceptionObject); } }
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { string fileName = Path.GetRandomFileName(); fileName = Path.Combine(System.Environment.CurrentDirectory, fileName); using (FileStream fStream = File.OpenWrite(fileName)) { StreamWriter sw = new StreamWriter(fStream); sw.WriteLine("Type is: " + e.GetType().FullName); sw.WriteLine("Exception object: "); sw.WriteLine(e.ExceptionObject); } MessageBox.Show( string.Format(System.Globalization.CultureInfo.InvariantCulture, "Unexpected error occurred in application initialization.\n\nAdditional information stored in file: " + fileName), string.Format(System.Globalization.CultureInfo.InvariantCulture, "Read Raw device") , MessageBoxButton.OK , MessageBoxImage.Error); }
/* private void txtDebugInput_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { if ((e.KeyCode == Keys.Enter) && e.Control) { try { XmlDocument doc = new XmlDocument(); doc.LoadXml(txtDebugInput.Text); XmlElement elem = doc.DocumentElement; if (elem != null) jc.Write(elem); txtDebugInput.Clear(); } catch (XmlException ex) { MessageBox.Show("Invalid XML: " + ex.Message); } } } */ private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { MessageBox.Show(e.ExceptionObject.ToString(), "Unhandled exception: " + e.GetType()); }