Static initializer gaurds

This commit is contained in:
Justin Aquadro 2012-10-04 22:26:57 -04:00
parent ef6102b0f4
commit 4949a35a84
3 changed files with 46 additions and 24 deletions

View file

@ -22,6 +22,7 @@ namespace NBTExplorer
static MainForm ()
{
try {
_tagIconIndex = new Dictionary<TagType, int>();
_tagIconIndex[TagType.TAG_BYTE] = 0;
_tagIconIndex[TagType.TAG_SHORT] = 1;
@ -35,6 +36,10 @@ namespace NBTExplorer
_tagIconIndex[TagType.TAG_COMPOUND] = 9;
_tagIconIndex[TagType.TAG_INT_ARRAY] = 14;
}
catch (Exception e) {
Program.StaticInitFailure(e);
}
}
public MainForm ()
{

View file

@ -45,6 +45,7 @@ namespace NBTExplorer.Model
static FileTypeRegistry ()
{
try {
Register<NbtFileDataNode>(new FileTypeRecord() {
NamePatternTest = NbtFileDataNode.SupportedNamePattern,
NodeCreate = NbtFileDataNode.TryCreateFrom,
@ -60,5 +61,9 @@ namespace NBTExplorer.Model
NodeCreate = CubicRegionDataNode.TryCreateFrom,
});
}
catch (Exception e) {
Program.StaticInitFailure(e);
}
}
}
}

View file

@ -16,5 +16,17 @@ namespace NBTExplorer
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public static void StaticInitFailure (Exception e)
{
Console.WriteLine("Static Initialization Failure:");
while (e != null) {
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
e = e.InnerException;
}
Application.Exit();
}
}
}