not familiar with JAVA or exception handling. Look for some advice on what is acceptable and what you frowned at.
The scenario, I am building a game of the life program, I have conditions set for checking whether a cell will be outside the borders and not trying to access this cell. My question is: is it acceptable to use a catch try block instead of 8 conditional expressions and just do nothing if an arrayOutOfBounds exception is thrown. those. ignore cells outside borders, or is it bad practice? eg...
try{
neighbors += cellIsAlive(row, col);
}catch(ArrayIndexOutofBoundsException e)
{
//dont do anything and continue counting neighbors
}
In this case, the cellIsAlive method checks the location in a multidimensional array and returns 1 if it is alive 0, and throws an ArrayIndexOutofBoundsException.
Is it a good idea or bad practice to use exceptions this way?
Thanks for any input.
source
share