Browse code

better exceptions

Adrian Papari authored on 17/07/2014 00:21:07
Showing 3 changed files
... ...
@@ -1,9 +1,18 @@
1 1
 package com.artemis;
2 2
 
3
+
3 4
 @SuppressWarnings("serial")
4 5
 public class MundaneWireException extends RuntimeException {
5 6
 
6 7
 	public MundaneWireException(Class<? extends EntityObserver> klazz) {
7 8
 		super(String.format("Not added to world: %s", klazz.getName()));
8 9
 	}
10
+
11
+	public MundaneWireException(String message, Throwable cause) {
12
+		super(message, cause);
13
+	}
14
+
15
+	public MundaneWireException(String message) {
16
+		super(message);
17
+	}
9 18
 }
... ...
@@ -664,7 +664,7 @@ public class World {
664 664
 					injectAnnotatedFields(target, clazz);
665 665
 				}
666 666
 			} catch (ReflectionException e) {
667
-				throw new RuntimeException("Error while wiring", e);
667
+				throw new MundaneWireException("Error while wiring", e);
668 668
 			}
669 669
 		}
670 670
 
... ...
@@ -688,6 +688,7 @@ public class World {
688 688
 
689 689
 		}
690 690
 
691
+		@SuppressWarnings("deprecation")
691 692
 		private void injectClass(Object target, Class<?> clazz) throws ReflectionException {
692 693
 			for (Field field : ClassReflection.getDeclaredFields(clazz)) {
693 694
 				if (field.hasAnnotation(Mapper.class) || field.hasAnnotation(Wire.class)) {
... ...
@@ -714,19 +715,19 @@ public class World {
714 715
 			if (ClassReflection.isAssignableFrom(ComponentMapper.class, fieldType)) {
715 716
 				ComponentMapper<?> mapper = world.getMapper(field.getElementType(0));
716 717
 				if (failOnNotInjected && mapper == null) {
717
-					throw new NullPointerException("ComponentMapper not found for " + fieldType);
718
+					throw new MundaneWireException("ComponentMapper not found for " + fieldType);
718 719
 				}
719 720
 				field.set(target, mapper);
720 721
 			} else if (ClassReflection.isAssignableFrom(EntitySystem.class, fieldType)) {
721 722
 				EntitySystem system = world.getSystem((Class<EntitySystem>)systems.get(fieldType));
722 723
 				if (failOnNotInjected && system == null) {
723
-					throw new NullPointerException("EntitySystem not found for " + fieldType);
724
+					throw new MundaneWireException("EntitySystem not found for " + fieldType);
724 725
 				}
725 726
 				field.set(target, system);
726 727
 			} else if (ClassReflection.isAssignableFrom(Manager.class, fieldType)) {
727 728
 				Manager manager = world.getManager((Class<Manager>)managers.get(fieldType));
728 729
 				if (failOnNotInjected && manager == null) {
729
-					throw new NullPointerException("Manager not found for " + fieldType);
730
+					throw new MundaneWireException("Manager not found for " + fieldType);
730 731
 				}
731 732
 				field.set(target, manager);
732 733
 			}
... ...
@@ -97,7 +97,7 @@ public class WireTest {
97 97
 		assertEquals(ComponentY.class, mappedSystem.y.get(entity).getClass());
98 98
 	}
99 99
 	
100
-	@Test(expected=NullPointerException.class)
100
+	@Test(expected=MundaneWireException.class)
101 101
 	public void ensure_inherited_systems_not_injected() {
102 102
 		World world = new World();
103 103
 		world.setSystem(new FailingSystem());
... ...
@@ -115,14 +115,14 @@ public class WireTest {
115 115
 		assertNull(failingSystem.x);
116 116
 	}
117 117
 	
118
-	@Test(expected=NullPointerException.class)
118
+	@Test(expected=MundaneWireException.class)
119 119
 	public void fail_on_system_not_injected() {
120 120
 		World world = new World();
121 121
 		FailingNpeSystem failingSystem = world.setSystem(new FailingNpeSystem());
122 122
 		world.initialize();
123 123
 	}
124 124
 	
125
-	@Test(expected=NullPointerException.class)
125
+	@Test(expected=MundaneWireException.class)
126 126
 	public void fail_on_manager_not_injected() {
127 127
 		World world = new World();
128 128
 		FailingNpeManager failingManager = world.setManager(new FailingNpeManager());