comparison FrmMainWindow.cs @ 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 4bad8cb3f889
comparison
equal deleted inserted replaced
46:3314f6a46661 47:07fd9f7b0dd1
25 using IBBoard.WarFoundry.API.Requirements; 25 using IBBoard.WarFoundry.API.Requirements;
26 using IBBoard.WarFoundry.GTK.Widgets; 26 using IBBoard.WarFoundry.GTK.Widgets;
27 using IBBoard.WarFoundry.Plugin.Rollcall; 27 using IBBoard.WarFoundry.Plugin.Rollcall;
28 using IBBoard.Xml; 28 using IBBoard.Xml;
29 using log4net; 29 using log4net;
30 using GLib;
30 31
31 namespace IBBoard.WarFoundry.GTK 32 namespace IBBoard.WarFoundry.GTK
32 { 33 {
33 public partial class FrmMainWindow: Gtk.Window 34 public partial class FrmMainWindow: Gtk.Window
34 { 35 {
51 private GameSystem system; 52 private GameSystem system;
52 private string loadedArmyPath; 53 private string loadedArmyPath;
53 54
54 private MenuToolButton undoMenuButton, redoMenuButton; 55 private MenuToolButton undoMenuButton, redoMenuButton;
55 56
56 public static void Main (string[] args) 57 public static void Main(string[] args)
57 { 58 {
58 try 59 try
59 { 60 {
61 ExceptionManager.UnhandledException += HandleUnhandledException;
60 Application.Init(); 62 Application.Init();
61 FrmMainWindow win = new FrmMainWindow(args); 63 FrmMainWindow win = new FrmMainWindow(args);
62 win.Show(); 64 win.Show();
63 Application.Run(); 65 Application.Run();
64 LogManager.GetLogger(typeof(FrmMainWindow)).Debug("Application ended"); 66 LogManager.GetLogger(typeof(FrmMainWindow)).Debug("Application ended");
65 } 67 }
66 catch(Exception ex) 68 catch(Exception ex)
67 { 69 {
68 LogManager.GetLogger(typeof(FrmMainWindow)).Fatal("("+ex.GetType().Name+") "+ex.Message + Environment.NewLine + ex.StackTrace); 70 HandleUnhandledException(ex);
69 } 71 }
72 }
73
74 private static void HandleUnhandledException(UnhandledExceptionArgs args)
75 {
76 object obj = args.ExceptionObject;
77 Exception ex = null;
78
79 if (obj is Exception)
80 {
81 ex = (Exception)obj;
82 }
83 else
84 {
85 ex = new Exception("GLib returned unexpected exception object type "+obj.GetType());
86 }
87
88 HandleUnhandledException(ex);
89 }
90
91 private static void HandleUnhandledException(Exception ex)
92 {
93 LogManager.GetLogger(typeof(FrmMainWindow)).Fatal("(" + ex.GetType().Name + ") " + ex.Message + Environment.NewLine + ex.StackTrace);
94 MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "An unhandled exception occurred. Please check the log for more details.");
95 dialog.Show();
70 } 96 }
71 97
72 public FrmMainWindow() : this(new string[0]) 98 public FrmMainWindow() : this(new string[0])
73 { 99 {
74 //Do nothing extra 100 //Do nothing extra