标题:小异常问题?
取消只看楼主
zhufeifei
Rank: 1
等 级:新手上路
威 望:2
帖 子:402
专家分:0
注 册:2006-8-11
 问题点数:0 回复次数:1 
小异常问题?

package Java_Think;
class Except1 extends Exception {
public Except1(String s) {
super(s);
}
}

class BaseWithException {
public BaseWithException() throws Except1 {
throw new Except1(
"thrown by BaseWithException");
}
}

class DerivedWE extends BaseWithException {
// Gives compile error:
// unreported exception Except1
// ! public DerivedWE() {}
// Gives compile error: call to super must be
// first statement in constructor:
//! public DerivedWE() {
//! try {
//! super();
//! } catch(Except1 ex1) {
//! }
//! }
public DerivedWE() throws Except1 {
throw new Except1("feifei");
}
}

public class E10_ConstructorExceptions {
public static void main(String args[]) {
try {
new DerivedWE();
} catch(Except1 ex1) {
System.out.println("Caught " + ex1.getMessage());
}
}
}
为什么输出的结果是:Caught thrown by BaseWithException
而不是:Caught feifei
谢了!!!!!!

搜索更多相关主题的帖子: class super package public 
2007-06-13 17:16
zhufeifei
Rank: 1
等 级:新手上路
威 望:2
帖 子:402
专家分:0
注 册:2006-8-11
得分:0 
明白,谢谢!呵呵~~~~~~~~~~

在不断的拼搏与进取中,定能创造一片天地!
2007-06-13 17:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-147196-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.345392 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved