Replace Exception with Test

You are throwing an exception on a condition the caller could have checked first.

Change the caller to make the test first.

double getValueForPeriod (int periodNumber) {
  try {
    return _values[periodNumber];
  } catch (ArrayIndexOutOfBoundsException e) {
    return 0;
  }
}

image/svg+xml

double getValueForPeriod (int periodNumber) {
  if (periodNumber >= _values.length) return 0;
  return _values[periodNumber];
}