public class JavaTest {
public static void main(String[] args) throws Throwable {
try {
throw new Throwable();
} catch(Exception e) {
System.err.println("Caught in main()");
}
}
}
为什么不能成功抛出异常?
------解决方案--------------------------------------------------------
这是因为Exception 是Throwable的子类,所以Exception无法捕获到Throwable,如果改成下面
- Java code
package csdn.p9;public class JavaTest { public static void main(String[] args) throws Throwable { try { throw new Throwable(); } catch(Throwable e) { System.err.println("Caught in main()"); } }}