java违例丢失BUG
上一篇 /
下一篇 2012-04-20 09:52:40
/ 个人分类:JAVA
package c9;
public class LostException {
/**
* @param args
*/
class Ex extends Exception{
public String toString(){
return "class Ex Exception";
}
}
class HostException extends Exception {
public String toString(){
return "class HostException Exception";
}
}
void f() throws Ex {
throw new Ex();
}
void g() throws HostException{
throw new HostException();
}
public static void main(String[] args) throws Exception {
LostException le= new LostException();
try{
le.f();
}
finally{
le.g();
}
}
}
运行结果是:
Exception in thread "main" class HostException Exception
at c9.LostException.g(LostException.java:27)
at c9.LostException.main(LostException.java:36)
这里面的 Ex违例被 finally 块中的 HostException 覆盖了,这意味着 违例会完全丢失!
收藏
举报
TAG: