add specific exception class for errors when using the service locator

This commit is contained in:
Gered 2013-08-25 14:59:31 -04:00
parent 825cee0dfc
commit c9b6279c2a
5 changed files with 27 additions and 3 deletions

View file

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

View file

@ -14,7 +14,7 @@ namespace Blarg.GameFramework.Graphics.Atlas
{
_contentManager = Framework.Services.Get<ContentManager>();
if (_contentManager == null)
throw new InvalidOperationException("Could not find ContentManager object.");
throw new ServiceLocatorException("Could not find a ContentManager object.");
_animations = new Dictionary<string, TextureAtlasTileAnimation>();
}

View file

@ -34,7 +34,7 @@ namespace Blarg.GameFramework.Graphics.Atlas
var contentManager = Framework.Services.Get<ContentManager>();
if (contentManager == null)
throw new InvalidOperationException("Cannot find a ContentManager object.");
throw new ServiceLocatorException("Could not find a ContentManager object.");
string textureFile = definition.Texture;
if (!String.IsNullOrEmpty(texturePath))

View file

@ -18,7 +18,7 @@ namespace Blarg.GameFramework.Graphics.ScreenEffects
_spriteBatch = Framework.Services.Get<SpriteBatch>();
if (_spriteBatch == null)
throw new InvalidOperationException("No SpriteBatch object registered with the service locator.");
throw new ServiceLocatorException("Could not find a SpriteBatch object.");
}
#region Get / Add / Remove

View file

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