大家帮我看下,下面这段代码,为什么会不能通过编译
package com;
class A extends Exception{
}
class B extends A{
}
public class Test {
public static void main(String args[]) {
try{
throw new B();
}catch(A a){
System.out.println("A is caught");
}catch(Exception a){
System.out.println("Exception is caught");
}
}
}
异常信息为:
Exception in thread "main" java.lang.VerifyError: (class: com/Test, method: main signature: ([Ljava/lang/String;)V) Can only throw Throwable objects
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getMethod0(Class.java:2685)
at java.lang.Class.getMethod(Class.java:1620)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:484)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:476)
难道异常不能多重继承? |