Skip to content

Commit

Permalink
Fix a bug where exception is not caught poperly but rethrown, fix #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimver committed Mar 6, 2018
1 parent dbaeadc commit a0a44ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 0 additions & 1 deletion JimsBackgroundChanger/DesktopWallpaper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public static void SystemEvents_DisplaySettingsChanged(object sender, EventArgs
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
SetSlideShow(settings, GetResolution());
}
Expand Down
26 changes: 15 additions & 11 deletions JimsBackgroundChanger/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// #define DEBUG

using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
Expand All @@ -17,28 +19,30 @@ static void Main()
//string path = Directory.GetCurrentDirectory();
//DateTime dt = DateTime.Now;
//File.AppendAllText("C:\\Users\\Jim\\jbcstart.txt", "[" + dt + "] Started from : " + path + Environment.NewLine);
string appPath = new Uri(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase) ?? throw new InvalidOperationException()).LocalPath;
string appPath = new Uri(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase) ??
throw new InvalidOperationException()).LocalPath;
Directory.SetCurrentDirectory(appPath);
//AppDomain currentDomain = AppDomain.CurrentDomain;
//currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += MyHandler;
SystemEvents.DisplaySettingsChanged += Wallpaper.SystemEvents_DisplaySettingsChanged;
Wallpaper.SystemEvents_DisplaySettingsChanged(null, EventArgs.Empty);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form());
}

/* Some debug code
private static void MyHandler(object sender, UnhandledExceptionEventArgs args)
// Catching exception globally
private static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
DateTime dt = DateTime.Now;
Exception e = (Exception)args.ExceptionObject;
Exception e = (Exception) args.ExceptionObject;
string msg = "[" + dt + "] MyHandler caught : " + e.Message + Environment.NewLine;
msg += $"Runtime terminating: {args.IsTerminating}";
Console.WriteLine(msg);
MessageBox.Show(msg, "ERROR");
File.AppendAllText("C:\\Users\\Jim\\jbclog.txt", msg + Environment.NewLine);
MessageBox.Show(msg, "Jim's background changer error");
#if DEBUG
File.AppendAllText("C:\\Users\\Jim\\Desktop\\jbclog.txt", msg + Environment.NewLine);
#endif
}
*/
}
}
}

0 comments on commit a0a44ef

Please sign in to comment.