Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
changeset 47:07fd9f7b0dd1
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 14 Aug 2010 19:56:08 +0000 |
parents | 3314f6a46661 |
children | 23238d998535 |
files | FrmMainWindow.cs |
diffstat | 1 files changed, 28 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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])