http://www.verejava.com/?id=16992970828178
package com.exception;
public class TestException
{
public static void main(String[] args)
{
//对运行期异常, 我们可以不捕获, 也可以捕获
int[] scores={60,70,80};
// java.lang.ArrayIndexOutOfBoundsException: 数组越界
try{ //试一试
System.out.println(scores[3]);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("发生了数组越界异常");
}
}
}
Java数组越界异常处理

本文介绍了一个简单的Java程序示例,演示了如何通过try-catch语句块来捕获并处理数组越界异常(ArrayIndexOutOfBoundsException)。这种异常通常发生在尝试访问数组中不存在的元素时。
6万+

被折叠的 条评论
为什么被折叠?



