Mercurial > repos > snowblizz-super-API-ideas
changeset 375:d9bf78a8f517
Re #351: Add extensible requirement handling method
* Wrap exception from integer parsing
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 02 Jul 2011 15:10:17 +0000 |
parents | 13793f3a2a2e |
children | e50682387d63 |
files | API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs |
diffstat | 1 files changed, 13 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs Sat Jul 02 14:59:45 2011 +0000 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs Sat Jul 02 15:10:17 2011 +0000 @@ -27,16 +27,26 @@ foreach (string requirement in data.Split('|')) { string[] requirementParts = requirement.Split(':'); - UnitType unitType = race.GetUnitType(requirementParts[0]); + string unitID = requirementParts[0]; + UnitType unitType = race.GetUnitType(unitID); if (unitType == null) { - throw new InvalidRequirementException(String.Format("Invalid unit type '{0}' for 'Requires at least N units' requirement", requirementParts[0])); + throw new InvalidRequirementException(String.Format("Invalid unit type '{0}' for 'Requires at least N units' requirement", unitID)); } if (requirementParts.Length == 2) { - req.AddUnitTypeRequirement(unitType, Int32.Parse(requirementParts[1])); + string amount = requirementParts[1]; + + try + { + req.AddUnitTypeRequirement(unitType, Int32.Parse(amount)); + } + catch (FormatException ex) + { + throw new InvalidRequirementException(String.Format("Invalid amount '{0}' for unit type '{1}' for 'Requires at least N units' requirement", amount, unitID)); + } } else {