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:

 

评分:0

我来说两句

日历

« 2024-05-08  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 20947
  • 日志数: 26
  • 建立时间: 2011-03-26
  • 更新时间: 2012-12-06

RSS订阅

Open Toolbar