More detailed exception reporting on crash.

This commit is contained in:
James Dunne
2012-07-03 15:37:37 -05:00
parent 8cea309ec6
commit b2e9085371

View File

@@ -13,6 +13,7 @@ using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using System.Text;
namespace OpenRA
{
@@ -37,11 +38,52 @@ namespace OpenRA
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 StringBuilder BuildExceptionReport(Exception e)
{
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));