62,628
社区成员
发帖
与我相关
我的任务
分享
public class C65
{
public void test() {
System.out.println("测试函数开始!");
try {
int x[] = new int[2];
System.out.println("int[2]=" + x[2]);
System.out.println("try块语句执行结束!");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.toString());
System.out.println("catch块语句执行结束!");
} finally {
System.out.println("finally块语句执行结束!");
}
System.out.println("测试函数结束!");
}
}

public class TestFinally {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
try{
throw new Exception("My Exception");
}catch(Exception e){
//throw e;
}finally{
System.out.println("Finally block done.");
}
System.out.println("Try block done.");
}
}
但是这样:
public class TestFinally {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
try{
throw new Exception("My Exception");
}catch(Exception e){
throw e;
}finally{
System.out.println("Finally block done.");
}
System.out.println("Try block done.");//Error
}
}
就报错了:Description Resource Path Location Type
Unreachable code TestFinally.java /Demo/src/other line 14 Java Problem
public static void main(String[] args) {
System.out.println("测试函数开始!");
try {
int x[] = null;
x.toString();
System.out.println("try块语句执行结束!");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.toString());
System.out.println("catch块语句执行结束!");
} finally {
System.out.println("finally块语句执行结束!");
}
System.out.println("测试函数结束!");
}
话说这些关键字翻译出来确实挺奇怪的说