Topic: 小小的问题 请路过的高手指点指点(extends Exception)

  Print this page

1.小小的问题 请路过的高手指点指点(extends Exception) Copy to clipboard
Posted by: cqhclys830
Posted on: 2006-08-15 16:48


class MyException extends Exception {
String msg;
public MyException(String msg) {
this.msg = msg;
}
public void printMsg() {
System.out.println("msg = " + msg);
}
}

// Or you can take a more clever approach, and
// note that string storage and printing is
// built into Exception:
class MyException2 extends Exception {
public MyException2(String s) {
//super(S);
super(s);
}
}

public class E02_ExceptionClass {
public static void main(String args[]) {
try {
throw new MyException(
"MyException message");
} catch(MyException e) {
e.printMsg();
}
try {
throw new MyException2(
"MyException2 message");
} catch(MyException2 e) {
System.out.println(
"e.getMessage() = " + e.getMessage());
}
}
} ///:~

为什么要用super(s) 在MyException2的基类中有 这个s吗?如果有怎么传过去的?
注销此行 e.getMessage()得到的是 null。

2.Re:小小的问题 请路过的高手指点指点(extends Exception) [Re: cqhclys830] Copy to clipboard
Posted by: why
Posted on: 2006-08-15 17:00

不太看得懂閣下想問甚麼Embaressed

MyException2的基类Exception有Exception() 和Exception(String)等constructors
注销那行則s無法传过去

3.Re:小小的问题 请路过的高手指点指点(extends Exception) [Re: cqhclys830] Copy to clipboard
Posted by: cqhclys830
Posted on: 2006-08-15 17:09

呵呵 你的回答使 已经很清楚了 我明白了
谢谢


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923