【发布时间】:2010-03-23 17:38:18
【问题描述】:
这样编译:
class Ex1 {
public int show() {
try {
int a=10/10;
return 10;
}
catch(ArithmeticException e) {
System.out.println(e);
}
finally {
System.out.println("Finally");
}
System.out.println("hello");
return 20;
}
}
另一方面,这不是:
class Ex15 {
public int show() {
try {
int a=10/0;
return 10;
}
catch(ArithmeticException e) {
System.out.println(e);
}
finally {
System.out.println("Finally");
return 40;
}
System.out.println("hello");
return 20;
}
}
并给出无法访问的语句 System.out.println("hello");错误。为什么会这样?
【问题讨论】:
-
编译器有什么错误?只是警告说 10/0 不是一个好主意?
-
由于 finally 中的返回,可能是关于无法访问代码块的警告。
-
请告诉我们编译器错误,否则将很难提供帮助。
-
@pablochan:只需在行首添加 4 个空格即可。
-
为什么这个问题是社区维基?
标签: java