了解异常处理模块中各个语句块的功能
编写TryTest.java 程序文件,源代码如下。
package Myjava;
import java.io.*;
public class TryTest{
public TryTest(){
try{
int a[] = new int[2];
a[4] = 3;
System.out.println("After handling exception return here?");
}catch(IndexOutOfBoundsException e){
System.err.println("exception msg:" + e.getMessage());
System.err.println("exception string:" + e.toString());
e.printStackTrace();
}finally{
System.out.println("-------------------");
System.out.println("finally");
}
System.out.println("No exception?");
}
public static void main(String args[]){
new TryTest();
}
}
运行结果:
exceptionmsg:4
exceptionstring:java.lang.ArrayIndexOutOfBoundsException: 4
java.lang.ArrayIndexOutOfBoundsException: 4
at Myjava.TryTest.<init>(TryTest.java:8)
at Myjava.TryTest.main(TryTest.java:21)
-------------------
finally
No exception?
请在实验报告中指出程序中的语句System.out.println("Afterhandling exception return here?"); 有没有被执行?
答:没有。