From: Charles Date: Thu, 15 Apr 2010 02:26:21 +0000 (+0000) Subject: getting entity lists not more consistent with throwing exceptions X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=2069ccccbb9dc0007f36555862615e684e93a8b2;p=chaz%2Fcarfire getting entity lists not more consistent with throwing exceptions git-svn-id: https://bd85.net/svn/cs3505_group@77 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs index c277a7a..3b10663 100644 --- a/CarFire/CarFire/CarFire/Map.cs +++ b/CarFire/CarFire/CarFire/Map.cs @@ -22,6 +22,30 @@ namespace CarFire // DEBUG: Tilesets not implemented at all. public static Texture2D DefaultTile; + #region Public Exceptions + + /// + /// This exception is thrown during the loading of a map if any + /// part of the map file is inconsistent with the expected format + /// and order. + /// + public class RuntimeException : System.ApplicationException + { + public RuntimeException() { } + + public RuntimeException(string message) : + base(message) { } + + public RuntimeException(string message, System.Exception inner) : + base(message, inner) { } + + protected RuntimeException(SerializationInfo info, StreamingContext context) : + base(info, context) { } + } + + #endregion + + #region Public Constants public const float PixelsToUnitSquares = 8.0f; @@ -288,9 +312,19 @@ namespace CarFire args[1] = raw.Position; args[2] = raw.Attributes; - object entity = Activator.CreateInstance(System.Type.GetType("CarFire." + typename), args); - if (entity != null) list.Add(entity); - else Console.WriteLine("Entity of type " + typename + " not loaded because an entity class can't be found."); + try + { + + object entity = Activator.CreateInstance(System.Type.GetType("CarFire." + typename), args); + if (entity != null) list.Add(entity); + else throw new RuntimeException(); + } +#pragma warning disable 0168 + catch (System.Exception ex) +#pragma warning restore 0168 + { + throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found."); + } } else { @@ -318,7 +352,7 @@ namespace CarFire T entity = (T)Activator.CreateInstance(type, args); if (entity != null) list.Add(entity); - else Console.WriteLine("Entity of type " + typename + " not loaded because an entity class can't be found."); + else throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found."); } }