标题: Exception 继承问题 [打印本页] 作者: fso918 时间: 2011-9-26 10:43 标题: Exception 继承问题 大家帮我看下,下面这段代码,为什么会不能通过编译
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)