Java String 类的 CharAt 方法抛出 StringIndexOutOfBoundsException。但是 Java API 文档说它会抛出一个IndexOutOfBoundsException
. 我知道那StringIndexOutOfBoundsException
是IndexOutOfBoundsException
. StringIndexOutOfBoundsException
但是 catch而不是不正确IndexOutOfBoundsException
吗?
这是charAt方法的代码
public char charAt(int index) {
if ((index < 0) || (index >= value.length)) {
throw new StringIndexOutOfBoundsException(index);
}
return value[index];
}