Say i have one method 'position', which takes 2 co-ordinates and creates a position object to hold them in. To make sure that these co-ordinates are not out of bounds, an InvalidPositionException is thrown.
public Position(int x, int y) throws InvalidPositionException {
try {
if (x > 10 || x < 1 || y>10 || y<1) {
throw new InvalidPositionException("Position x = "+x+", y = "+y+" is out of bounds");
} else {
setX(x);
setY(y);
}
} catch (InvalidPositionException e) {
System.err.println(e);
}
}
If I now want to create a new position object from another class, I get the error message "unreported exception InvalidPositionException; must be caught or declared to be thrown"
How can I make this work without declaring "throws" in the method signature of the method creating the new position object?