From da0b4ecd3bc23e979802c31c7e66c7d6e8d6fef1 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Thu, 2 May 2013 23:45:05 +1200 Subject: [PATCH] Log unhandled exceptions --- OpenRA.Game/Support/Program.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Support/Program.cs b/OpenRA.Game/Support/Program.cs index 181be6b7cd..78d065ab9a 100644 --- a/OpenRA.Game/Support/Program.cs +++ b/OpenRA.Game/Support/Program.cs @@ -12,8 +12,8 @@ using System; using System.Diagnostics; using System.Globalization; using System.Linq; -using System.Windows.Forms; using System.Text; +using System.Windows.Forms; namespace OpenRA { @@ -31,19 +31,26 @@ namespace OpenRA return; } + AppDomain.CurrentDomain.UnhandledException += (_, e) => LogException((Exception)e.ExceptionObject); + try { Run(args); } catch (Exception e) { - Log.AddChannel("exception", "exception.log"); - var rpt = BuildExceptionReport(e).ToString(); - Log.Write("exception", "{0}", rpt); - Console.Error.WriteLine(rpt); + LogException(e); } } + static void LogException(Exception e) + { + Log.AddChannel("exception", "exception.log"); + var rpt = BuildExceptionReport(e).ToString(); + Log.Write("exception", "{0}", rpt); + Console.Error.WriteLine(rpt); + } + static StringBuilder BuildExceptionReport(Exception e) { return BuildExceptionReport(e, new StringBuilder(), 0);