Beispiel #1
0
        /// <summary>
        /// 处理非UI线程异常
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception;

            LogHelper.WriteLog(e.GetType(), ex);
            CommonUtil.WriteLog(ex);
            Msg.ShowError(ex.Message);
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
 /*
  * 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());
 }
Beispiel #5
0
 /// <summary>
 /// 处理未捕获的异常
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     LogHelper.Error(e.GetType(), "终止?" + e.IsTerminating + (e.ExceptionObject as Exception).ToString());
 }
Beispiel #6
0
        public static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var errorMessage = string.Format("An unrecoverable error has occurred. We are sorry.");
            // having a messagebox before the window initializes causes an exception of its own.
            //MessageBox.Show(errorMessage, "Application Error", MessageBoxButton.OK, MessageBoxImage.Error);

            // log it
            var exceptionType = ExceptionHelper.WriteExceptionDetails(e.ExceptionObject as Exception);
            var date          = string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now);
            var assembly      = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).AbsolutePath;
            var dir           = Path.GetDirectoryName(assembly);
            var logPath       = Path.Combine(dir, String.Format(@"Exception {0} {1}.txt", date, e.GetType()));

            logPath = Path.GetInvalidPathChars()
                      .Aggregate(logPath, (current, c) => current.Replace(c.ToString(), string.Empty));
            File.WriteAllText(new Uri(logPath).LocalPath, exceptionType);

            Process.Start(logPath);
        }