Skip to content

Commit

Permalink
Handle unhandled exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelKlaer committed May 3, 2023
1 parent 572a0f5 commit 649724e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Minesweeper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ internal static class Program
/// </summary>
[STAThread]
private static void Main()
{
// Handle unhandled exceptions
try
{
Run();
}
catch (Exception ex)
{
DialogResult res = MessageBox.Show($"{ex.Message}\n\nStacktrace:\n{ex.StackTrace}\n\n- Click yes to copy to clipboard", "Unhandled Exception", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (res == DialogResult.Yes) Clipboard.SetText($"Unhandled Exception:\n\n{ex.Message}\n\nStacktrace:\n{ex.StackTrace}");
}
}

/// <summary>
/// Run the application
/// </summary>
private static void Run()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
Expand Down

0 comments on commit 649724e

Please sign in to comment.