The question is if it is prefered to Throw
an exception
or to prevent it from ever occurring. It is for a game project.
IndexOutOfBoundsException
vs. coding around it.
I have a List<E>
private Attribute<List> attributes;
A method to get an item by index.
public Attribute getAttribute (int index) {
if (index < 0 || index >= attributes.size())
index = 0;
return attributes.get(index);
}
In this case I am defaulting to the 1st element of the list.