写了个差不多的异常,为什么会报错?求大神解答
package exception;
public class Exception {
public static void main(String[] args) {
// TODO Auto-generated method stub
Exception tct =new Exception();
int result = 0;
result = tct.test1();
System.out.println("result= "+result);
}
public int test1(){
int div = 10;
int result = 100;
try{while(div>-1)
{div--;
result= result + 100/div;}
return result;
}catch(Exception e){
e.printStackTrace();
System.out.println("捕获异常");
return -1;
}
}
}
问题出在了catch(Exception e),编译器错误的提示信息是;No exception of type Exception can be thrown; an exception type must be a subclass of Throwable。