-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (41 loc) · 1.79 KB
/
Copy pathProgram.cs
File metadata and controls
47 lines (41 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using DuckSQL.Analytics;
using DuckSQL.Helpers;
namespace DuckSQL
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
RouteUnhandledExceptions();
Application.Run(new MainForm());
}
/// <summary>
/// When called, all unhandled exceptions within the runtime and winforms UI thread
/// will be routed to <see cref="ExceptionHandler"/>.
/// </summary>
/// <remarks>Side effect: The application will never quit when an unhandled exception happens.</remarks>
private static void RouteUnhandledExceptions()
{
//If we're not debugging, route all unhandled exceptions to our top level exception handler
if (!System.Diagnostics.Debugger.IsAttached)
{
// Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException += new((sender, e) => ExceptionHandler((Exception)e.ExceptionObject));
// Add the event handler for handling UI thread exceptions to the event.
// Warning: Winforms only surfaces the inner-most exception to this handler.
Application.ThreadException += new((sender, e) => ExceptionHandler(e.Exception));
}
}
private static void ExceptionHandler(Exception ex)
{
ExceptionEvent.FireAndForget(ex);
MessageBox.Show($"{Resources.Errors.GenericErrorMessage} {Resources.Errors.CopyErrorMessageText}:{Env.DoubleNewLine}{ex}",
ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}