# HG changeset patch # User IBBoard # Date 1281815768 0 # Node ID 07fd9f7b0dd1a7649d2e79a896ca2d21d5285601 # Parent 3314f6a46661d677f55ea4615b38b6ac948a4746 Re #79: Make use of GTK# callback for exceptions * Hook up method to event * Add dialog on unhandled exception so that the user knows Note: Still prints lots of stack trace about GLib stuff, but I don't know if that's normal yet diff -r 3314f6a46661 -r 07fd9f7b0dd1 FrmMainWindow.cs --- a/FrmMainWindow.cs Sat Aug 14 19:25:08 2010 +0000 +++ b/FrmMainWindow.cs Sat Aug 14 19:56:08 2010 +0000 @@ -27,6 +27,7 @@ using IBBoard.WarFoundry.Plugin.Rollcall; using IBBoard.Xml; using log4net; +using GLib; namespace IBBoard.WarFoundry.GTK { @@ -53,10 +54,11 @@ private MenuToolButton undoMenuButton, redoMenuButton; - public static void Main (string[] args) + public static void Main(string[] args) { try { + ExceptionManager.UnhandledException += HandleUnhandledException; Application.Init(); FrmMainWindow win = new FrmMainWindow(args); win.Show(); @@ -65,8 +67,32 @@ } catch(Exception ex) { - LogManager.GetLogger(typeof(FrmMainWindow)).Fatal("("+ex.GetType().Name+") "+ex.Message + Environment.NewLine + ex.StackTrace); + HandleUnhandledException(ex); + } + } + + private static void HandleUnhandledException(UnhandledExceptionArgs args) + { + object obj = args.ExceptionObject; + Exception ex = null; + + if (obj is Exception) + { + ex = (Exception)obj; } + else + { + ex = new Exception("GLib returned unexpected exception object type "+obj.GetType()); + } + + HandleUnhandledException(ex); + } + + private static void HandleUnhandledException(Exception ex) + { + LogManager.GetLogger(typeof(FrmMainWindow)).Fatal("(" + ex.GetType().Name + ") " + ex.Message + Environment.NewLine + ex.StackTrace); + MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "An unhandled exception occurred. Please check the log for more details."); + dialog.Show(); } public FrmMainWindow() : this(new string[0])