Method CharAt of the Java String class throws a StringIndexOutOfBoundsException. But the Java API documentation says it throws an IndexOutOfBoundsException
. I know that StringIndexOutOfBoundsException
is a subclass of IndexOutOfBoundsException
. But is it incorrect to catch StringIndexOutOfBoundsException
instead of IndexOutOfBoundsException
?
Here is the code of the charAt method
public char charAt(int index) {
if ((index < 0) || (index >= value.length)) {
throw new StringIndexOutOfBoundsException(index);
}
return value[index];
}