]> Dogcows Code - chaz/carfire/commitdiff
getting entity lists not more consistent with throwing exceptions
authorCharles <Charles@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 15 Apr 2010 02:26:21 +0000 (02:26 +0000)
committerCharles <Charles@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 15 Apr 2010 02:26:21 +0000 (02:26 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@77 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/Map.cs

index c277a7aa4590633359fd50a7d7ef9349f0ec0eff..3b10663d089a9f06242b68aa0082625a40876cf5 100644 (file)
@@ -22,6 +22,30 @@ namespace CarFire
         // DEBUG: Tilesets not implemented at all.\r
         public static Texture2D DefaultTile;\r
 \r
+        #region Public Exceptions\r
+\r
+        /// <summary>\r
+        /// This exception is thrown during the loading of a map if any\r
+        /// part of the map file is inconsistent with the expected format\r
+        /// and order.\r
+        /// </summary>\r
+        public class RuntimeException : System.ApplicationException\r
+        {\r
+            public RuntimeException() { }\r
+\r
+            public RuntimeException(string message) :\r
+                base(message) { }\r
+\r
+            public RuntimeException(string message, System.Exception inner) :\r
+                base(message, inner) { }\r
+\r
+            protected RuntimeException(SerializationInfo info, StreamingContext context) :\r
+                base(info, context) { }\r
+        }\r
+\r
+        #endregion\r
+\r
+\r
         #region Public Constants\r
 \r
         public const float PixelsToUnitSquares = 8.0f;\r
@@ -288,9 +312,19 @@ namespace CarFire
                         args[1] = raw.Position;\r
                         args[2] = raw.Attributes;\r
 \r
-                        object entity = Activator.CreateInstance(System.Type.GetType("CarFire." + typename), args);\r
-                        if (entity != null) list.Add(entity);\r
-                        else Console.WriteLine("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
+                        try\r
+                        {\r
+\r
+                            object entity = Activator.CreateInstance(System.Type.GetType("CarFire." + typename), args);\r
+                            if (entity != null) list.Add(entity);\r
+                            else throw new RuntimeException();\r
+                        }\r
+#pragma warning disable 0168\r
+                        catch (System.Exception ex)\r
+#pragma warning restore 0168\r
+                        {\r
+                            throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
+                        }\r
                     }\r
                     else\r
                     {\r
@@ -318,7 +352,7 @@ namespace CarFire
 \r
                         T entity = (T)Activator.CreateInstance(type, args);\r
                         if (entity != null) list.Add(entity);\r
-                        else Console.WriteLine("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
+                        else throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
                     }\r
                 }\r
 \r
This page took 0.027723 seconds and 4 git commands to generate.