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类型的异常,到我这怎么就出错了,求高手解答,谢谢!
{
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类型的异常,到我这怎么就出错了,求高手解答,谢谢!
=>
private static void throwit()
去掉这个
new java.lang.RuntimeException()