diff --git a/ShareX/Program.cs b/ShareX/Program.cs index a52c03309..af3a8ebb8 100644 --- a/ShareX/Program.cs +++ b/ShareX/Program.cs @@ -267,19 +267,9 @@ public static string ScreenshotsParentFolder [STAThread] private static void Main(string[] args) { - // Allow Visual Studio to break on exceptions in Debug builds -#if !DEBUG - // Add the event handler for handling UI thread exceptions to the event - Application.ThreadException += Application_ThreadException; + HandleExceptions(); - // Set the unhandled exception mode to force all Windows Forms errors to go through our handler - Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); - - // Add the event handler for handling non-UI thread exceptions to the event - AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; -#endif - - StartTimer = Stopwatch.StartNew(); // For be able to show startup time + StartTimer = Stopwatch.StartNew(); CLI = new ShareXCLIManager(args); CLI.ParseCommands(); @@ -625,6 +615,25 @@ public static bool WritePersonalPathConfig(string path) return false; } + private static void HandleExceptions() + { +#if DEBUG + if (Debugger.IsAttached) + { + return; + } +#endif + + // Add the event handler for handling UI thread exceptions to the event + Application.ThreadException += Application_ThreadException; + + // Set the unhandled exception mode to force all Windows Forms errors to go through our handler + Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); + + // Add the event handler for handling non-UI thread exceptions to the event + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + } + private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { OnError(e.Exception);