Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- string msg = null;
- try
- {
- if (e.ExceptionObject is Exception)
- {
- Exception ex = (Exception) e.ExceptionObject;
- msg = renderException(ex);
- }
- else
- {
- msg = e.ExceptionObject.ToString();
- }
- CFAPControlLibrary.Service<ICFAPService>.Use(srv =>
- {
- srv.Log(string.Format("Unhandled exception in client: " + msg)); // wcf service call
- });
- }
- catch
- {
- // couldn't save the exception details at provider side
- if (msg != null)
- {
- File.AppendAllText("error.log", msg);
- }
- }
- try
- {
- if (File.Exists(dumperPath)) // path to procdump.exe
- {
- DirectoryInfo di = new DirectoryInfo(dumperPath);
- string args = string.Format("-ma -accepteula {0}", System.AppDomain.CurrentDomain.FriendlyName);
- Process.Start(di.FullName, args);
- }
- }
- catch
- {
- // coudn't write crash dump, no way to handle this
- }
- }
- string renderException(Exception e, StringBuilder sw = null)
- {
- if (sw == null)
- {
- sw = new StringBuilder();
- }
- sw.AppendLine(e.GetType().ToString());
- sw.AppendLine(e.Message);
- sw.AppendLine(e.StackTrace);
- if (e.InnerException != null)
- {
- sw.AppendLine("Inner exception: ");
- renderException(e.InnerException, sw);
- }
- return sw.ToString();
- }A
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement