详细页面:http://www.verydemo.com/demo_c89_i59821.html
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 覆盖了,这意味着 违例会完全丢失!