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类的抛出异常?
请大侠赐教!!!
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类的抛出异常?
请大侠赐教!!!
楼主【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 %
值得尊敬
river.flow(water, warn);
}
throws Exception什么意思
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();
}
}
}