源程序如下
public class Rethrowing {
public static void f() throws Exception {
System.out.println(
"originating the exception in f()");
throw new Exception("thrown from f()");
}
public static void g() throws Throwable {
try {
f();
} catch(Exception e) {
System.err.println(
"Inside g(), e.printStackTrace()");
e.printStackTrace(System.err);
throw e; // 17
//throw e.fillInStackTrace(); // 18
}
}
public static void
main(String[] args) throws Throwable {
try {
g();
} catch(Exception e) {
System.err.println(
"Caught in main, e.printStackTrace()");
e.printStackTrace(System.err);
}
}
} ///:~ 我要问的是为什么在g()这个函数中申明了抛出Throwable这个例外,可是在main()中的try并没有捕捉Throwable这个例外,这怎么可以呢?
public class Rethrowing {
public static void f() throws Exception {
System.out.println(
"originating the exception in f()");
throw new Exception("thrown from f()");
}
public static void g() throws Throwable {
try {
f();
} catch(Exception e) {
System.err.println(
"Inside g(), e.printStackTrace()");
e.printStackTrace(System.err);
throw e; // 17
//throw e.fillInStackTrace(); // 18
}
}
public static void
main(String[] args) throws Throwable {
try {
g();
} catch(Exception e) {
System.err.println(
"Caught in main, e.printStackTrace()");
e.printStackTrace(System.err);
}
}
} ///:~ 我要问的是为什么在g()这个函数中申明了抛出Throwable这个例外,可是在main()中的try并没有捕捉Throwable这个例外,这怎么可以呢?
解决方案 »
- Permgen OutOfMemory,请问有什么手段或者工具可以看到Permgen中被intern()的String的具体内容
- 怎么让我的代码运行 ? 路径怎么添加进去 ?
- java中的内部类
- 一个页面上有多个 <html:image>怎么知道点的是那个呢?
- (与初学者分享,高手都会,但高手不一定与初学者分享源码)解决java压缩,解压中文目录、文件名问题。
- 关于Thread类的控制问题。。。凡答复必加分!!!
- 我写的扫雷,要的进来,来的有分,黑黑
- 怎样设置JTree的某个节点为选中状态?
- 想找些代码研习一下,大家给点意见,有哪些适合菜鸟的代码?
- 面向对象不是万能的
- 只有两处错误了,帮帮我吧。
- 请教怎样在XP下设置\运行java//详细点
我还是不明白?