For example, I have a parent class that is constructed as:
public class ArrayIndexedList<T> implements IndexedList<T> {
private final T[] data;
public ArrayIndexedList(int size, T defaultValue) throws LengthException {
if (size <= 0) {
throw new LengthException();
}
if (defaultValue == null) {
return;
}
for (int i = 0; i < size; i++) {
data[i] = defaultValue;
}
}
}
And I have a subclass that extends this class constructed as following:
public class MeasuredIndexedList<T> extends ArrayIndexedList<T> {
private int accessCount;
private int mutationCount;
public MeasuredIndexedList(int size, T defaultValue) {
super(size, defaultValue); //how to take the exception thrown by this line?
accessCount = 0;
mutationCount = 0;
}
}
What is the most appropriate way that I can handle the exception form calling the super constructor while not changing the declaration of the subclass constructor?