public class RuntimeException { private static void throwit() throws Exception
{
System.out.print("throwit ");
//throw new Exception();
throw new RuntimeException(); /* eclipse中提示这句代码有误,给出的错误提示是“No exception of    type RuntimeException can be thrown; an exception type must be a subclass of Throwable” */
}

public static void main(String[] args) {

try
{
System.out.print("try ");
throwit();
}
catch(Exception e)
{
System.out.print("catch ");
}
finally
{
System.out.print("finally ");
}
System.out.println("last");
}
}上述程序中,代码 throw new RuntimeException(); 在 eclipse中提示这句代码有误,给出的错误提示是“No exception of    type RuntimeException can be thrown; an exception type must be a subclass of Throwable” 
网上查看到可以抛出RuntimeException类型的异常,到我这怎么就出错了,求高手解答,谢谢!

解决方案 »

  1.   

    方法声明中throws出的是checked exception。RuntimeException及其子类是non-checked exception。 private static void throwit() throws Exception
    =>
     private static void throwit()
    去掉这个
      

  2.   

    LZ啊,你自己的类名就叫RuntimeException,你这个类又不是Throwable的子类,怎么作为异常抛出你要不肯改名,就试试这样:
    new java.lang.RuntimeException()