课堂实践
实现一个可以检测数组越界的异常检测程序。
public class Example {
public static void main(String[] args) {
int a[]=new int[2];
try {
System. out. println("Access element three:"+a[3]);
} catch (Exception e)
//catch(ArrayIndexOutOfBoundsException e)
{
System. out. println("Exception thrown:"+e.getMessage());
}
}
}