public class YellowRiver extends River{
private int warning;                          //警戒水位
private int waterLine;                        //当前水位

public YellowRiver(int water,int warn){
water=waterLine;
warn=warning;
}

public void flow(int water,int warn) throws Exception{
if(water<=warn){
System.out.println("黄河在流:黄河之水天上来,奔流到海不复回。");
}else if(water>(warn+5)){
water=waterLine;
warn=warning;
throw new Exception("黄河决堤了。");
}
}
}public class GCD {
int water;
int warn;

public void watch(River river) throws Exception{
river.flow(water, warn);
}

public static void main(String[] args){
try{
GCD obj3=new GCD();
obj3.watch(new YellowRiver(30,10));
}catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
为什么GCD类捕获不到YellowRiver类的抛出异常?
请大侠赐教!!!

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【heroblues】截止到2008-07-10 14:57:36的历史汇总数据(不包括此帖):
    发帖的总数量:21                       发帖的总分数:240                      每贴平均分数:11                       
    回帖的总数量:15                       得分贴总数量:2                        回帖的得分率:13%                      
    结贴的总数量:20                       结贴的总分数:220                      
    无满意结贴数:9                        无满意结贴分:145                      
    未结的帖子数:1                        未结的总分数:20                       
    结贴的百分比:95.24 %               结分的百分比:91.67 %                  
    无满意结贴率:45.00 %               无满意结分率:65.91 %                  
    值得尊敬
      

  2.   

    throw new Exception("黄河决堤了。");  老大,你这个都错了吧,应该是throw new RuntimeException("黄河决堤了。"); 运行时异常才对。这样写程序,黄河都把你淹死了他都不报警!
      

  3.   

    public void watch(River river) throws Exception{ 
    river.flow(water, warn); 

    throws Exception什么意思
      

  4.   

    因为你在watch中river.flow(water, warn); 的water和warn是GCD的变量,你又没赋值,它们都是0,所以不会抛出异常
      

  5.   

    你的类也写得够烂的哦,我重新给你编写一下public class YellowRiver extends River{ 
    private int warning;                          //警戒水位 
    private int waterLine;                        //当前水位 public YellowRiver(int water,int warn){ 
    waterLine=water; //这里你都写反了
    warning=warn; 
    } public void flow() throws Exception{ 
    if(waterLine<=warning){ 
    System.out.println("黄河在流:黄河之水天上来,奔流到海不复回。"); 
    }else if(waterLine>(warning+5)){ 
    throw new Exception("黄河决堤了。"); 
    } else{//这里你还需要出来,难道不处理了??
       System.out.println("NND,已经超过警戒水位了");
    }

    } public class GCD { 
    public void watch(River river) throws Exception{ 
    river.flow(); 
    } public static void main(String[] args){ 
    try{ 
    GCD obj3=new GCD(); 
    obj3.watch(new YellowRiver(30,10)); 
    }catch(Exception e){ 
    System.out.println(e.getMessage()); 
    e.printStackTrace();