static void methodA(){
try{
System.out.println("进入方法A");
throw new RuntimeException("制造异常");
}finally{
System.out.println("用A方法的finally");
}
}
public static void main(String[] args) {
try{
methodA();
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
这是在学异常处理写的一段代码,在main函数里catch结构写Exception会报错:No exception of type Exception can be thrown; an exception type must be a subclass of Throwable
就很奇怪,写RuntimeExceprion就没事。这是为啥啊?我用eclipse写的
写RuntimeExceprion你的运行结果是那两个sout吗
继承关系 没有错
异常的抛出是有一个严谨的结构的,必须是从小到大进行抛出。