# HG changeset patch # User IBBoard # Date 1254252110 0 # Node ID 62ff1ac132d2ff1c79031e424d08b93e18ddc647 # Parent df61d26c23fb635f8472a0251840c82596d17e6c Fixes #185: Problems with decimals in race definitions * Problem fixed with ibboard:r103 (XmlTools were using int.parse in double parsing code!) * Catch and wrap exceptions so that they get caught with a dialog for the user diff -r df61d26c23fb -r 62ff1ac132d2 api/Factories/Xml/WarFoundryXmlRaceFactory.cs --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Mon Sep 28 19:48:37 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Tue Sep 29 19:21:50 2009 +0000 @@ -123,20 +123,28 @@ } private void LoadCoreValuesForUnitType(XmlElement elem, UnitType type) - { - type.MaxNumber = XmlTools.GetIntValueFromAttribute(elem, "maxNum"); - type.MinNumber = XmlTools.GetIntValueFromAttribute(elem, "minNum"); - type.MaxSize = XmlTools.GetIntValueFromAttribute(elem, "maxSize"); - type.MinSize = XmlTools.GetIntValueFromAttribute(elem, "minSize"); - type.BaseSize = XmlTools.GetIntValueFromAttribute(elem, "baseSize"); - type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points"); - type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "unitPoints"); + { + try + { + type.MaxNumber = XmlTools.GetIntValueFromAttribute(elem, "maxNum"); + type.MinNumber = XmlTools.GetIntValueFromAttribute(elem, "minNum"); + type.MaxSize = XmlTools.GetIntValueFromAttribute(elem, "maxSize"); + type.MinSize = XmlTools.GetIntValueFromAttribute(elem, "minSize"); + type.BaseSize = XmlTools.GetIntValueFromAttribute(elem, "baseSize"); + type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points"); + type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "unitPoints"); + } + catch (FormatException ex) + { + throw new InvalidDataException(ex.Message, ex); + } + string mainCatID = elem.GetAttribute("cat"); Category cat = type.Race.GetCategory(mainCatID); if (cat == null) { - throw new InvalidDataException(String.Format("Attribute 'cat' of UnitType {0} (value: {1}) did not reference a valid category", type.ID, mainCatID)); + throw new InvalidDataException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, mainCatID)); } type.MainCategory = cat;