add specific exception for errors when parsing config files

This commit is contained in:
Gered 2013-08-25 15:01:39 -04:00
parent c9b6279c2a
commit 340bebe354
3 changed files with 26 additions and 3 deletions

View file

@ -193,6 +193,7 @@
<Compile Include="Graphics\Atlas\JsonTextureAtlasTile.cs" />
<Compile Include="Graphics\Atlas\TextureAtlasLoader.cs" />
<Compile Include="ServiceLocatorException.cs" />
<Compile Include="ConfigFileException.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>

View file

@ -0,0 +1,23 @@
using System;
namespace Blarg.GameFramework
{
public class ConfigFileException : Exception
{
public ConfigFileException()
: base()
{
}
public ConfigFileException(String message)
: base(message)
{
}
public ConfigFileException(String message, Exception innerException)
: base(message, innerException)
{
}
}
}

View file

@ -24,13 +24,12 @@ namespace Blarg.GameFramework.Graphics.Atlas
throw new ArgumentNullException("file");
var reader = new StreamReader(file);
var definition = JsonConvert.DeserializeObject<JsonTextureAtlasDefinition>(reader.ReadToEnd());
if (definition.Texture == null)
throw new Exception("No texture file specified.");
throw new ConfigFileException("No texture file specified.");
if (definition.Tiles == null || definition.Tiles.Count == 0)
throw new Exception("No tiles defined.");
throw new ConfigFileException("No tiles defined.");
var contentManager = Framework.Services.Get<ContentManager>();
if (contentManager == null)