Java 错误有关问题

Java 异常问题public class JavaTest {public static void main(String[] args) throws Throwable {try {t

Java 异常问题
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()");        }    }}