Is it OK to use exceptions to check for array boundaries?
I want to check whether the given coordinates are withing an array or not.
Can I do it like that?
public boolean checkBounds(int x, int y) {
try {
Object val = array[x][y];
return true;
} catch (ArrayIndexOutOfBoundsException e) {
return false;
}
}
No comments:
Post a Comment