diff --git a/OpenRA.Game/Support/Program.cs b/OpenRA.Game/Support/Program.cs index 5e3468f06d..4b136a29dc 100644 --- a/OpenRA.Game/Support/Program.cs +++ b/OpenRA.Game/Support/Program.cs @@ -13,13 +13,14 @@ using System.Diagnostics; using System.Globalization; using System.Linq; using System.Windows.Forms; +using System.Text; namespace OpenRA { static class Program { [STAThread] - static void Main( string[] args ) + static void Main(string[] args) { // brutal hack Application.CurrentCulture = CultureInfo.InvariantCulture; @@ -32,19 +33,60 @@ namespace OpenRA try { - Run( args ); + Run(args); } - catch( Exception e ) + catch (Exception e) { Log.AddChannel("exception", "exception.log"); - Log.Write("exception", "{0}", e.ToString()); - throw; + var rpt = BuildExceptionReport(e).ToString(); + Log.Write("exception", "{0}", rpt); + Console.Error.WriteLine(rpt); } } - static void Run( string[] args ) + static StringBuilder BuildExceptionReport(Exception e) { - Game.Initialize( new Arguments(args) ); + return BuildExceptionReport(e, new StringBuilder(), 0); + } + + static void Indent(StringBuilder sb, int d) + { + sb.Append(new string(' ', d * 2)); + } + + static StringBuilder BuildExceptionReport(Exception e, StringBuilder sb, int d) + { + if (e == null) return sb; + + sb.AppendFormat("Exception of type `{0}`: {1}", e.GetType().FullName, e.Message); + + TypeLoadException tle; + if ((tle = e as TypeLoadException) != null) + { + sb.AppendLine(); + Indent(sb, d); + sb.AppendFormat("TypeName=`{0}`", tle.TypeName); + } + else // TODO: more exception types + { + } + + if (e.InnerException != null) + { + sb.AppendLine(); + Indent(sb, d); sb.Append("Inner "); + BuildExceptionReport(e.InnerException, sb, d + 1); + } + + sb.AppendLine(); + Indent(sb, d); sb.Append(e.StackTrace); + + return sb; + } + + static void Run(string[] args) + { + Game.Initialize(new Arguments(args)); GC.Collect(); Game.Run(); }