Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Rapr/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Reflection;
using System.Security;
using System.Threading;
using System.Windows.Forms;

using Rapr.Lang;
Expand Down Expand Up @@ -72,6 +73,25 @@ private static void CleanUpOldConfig()
}
}

internal static void LogUnhandledException(object exception)
{
Trace.TraceError($"Unhandled exception: {exception}");
}

private static void OnThreadException(object sender, ThreadExceptionEventArgs e)
{
LogUnhandledException(e.Exception);

// Same dialog WinForms shows when there is no handler.
using (var dialog = new ThreadExceptionDialog(e.Exception))
{
if (dialog.ShowDialog() == DialogResult.Abort)
{
Application.Exit();
}
}
}

/// <summary>
/// The main entry point for the application.
/// </summary>
Expand All @@ -85,6 +105,11 @@ public static void Main()
Trace.IndentSize = 4;
Trace.Listeners.Add(new TextFileTraceListener());

// Write crashes to Rapr.log; otherwise a crash during startup leaves nothing to report.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += OnThreadException;
AppDomain.CurrentDomain.UnhandledException += (sender, e) => LogUnhandledException(e.ExceptionObject);

AddEnvironmentPaths(@"C:\Windows\System32\CompatTel");

UpdateManager.CleanUpOldFiles();
Expand Down
Loading