java的一些题目
T0开荒 2011-09-27 10:57:40 阅读程序题, 写出结果并写出原因
class MyException extends Exception {
public MyException(String message) {
super(message);
}
}
public class Test {
private static void fun1() throws MyException {
throw new MyException("An MyException object is thrown in fun1().");
}
private static void fun2() throws MyException {
try {
fun1();
}
catch(NullPointerException ex) {
System.out.println("NullPointerException:"+ex.getMessage());
}
finally {
System.out.println("Go through finally code in fun2().");
}
}
public static void main (String[] args) {
try {
fun2();
}
catch(MyException ex) {
System.out.println("MyException:"+ex.getMessage());
}
catch(Exception ex) {
System.out.println("Exception:"+ex.getMessage());
}
}
}