UnchartedTerritoryException.java:
package territory;
/**
* Thrown when the Location of a Wanderer object in a Territory is outside the
* boundaries of the Territory.
**/
public class UnchartedTerritoryException extends RuntimeException {
public UnchartedTerritoryException(int x, int y) {
System.out.println("Invalid coordinates " + x + ", " + y);
}
}
drawWanderer method in Territory.java
if ((posX < 0 || posX >= TERRITORY_WIDTH) ||
(posY < 0 || posY >= TERRITORY_HEIGHT)) {
// ... graphics code omitted ...
// draw a dead wanderer and throw exception
// ... more graphics code omitted ...
throw new UnchartedTerritoryException(posX, posY);
}