每天学点Java知识 ------> throws关键字
上一篇 /
下一篇 2014-07-23 16:37:56
/ 个人分类:Java学习
throws关键字主要是在方法定义上使用的,表示此方法中不进行异常的处理,而交给被调用处处理
例:调用throws声明的方法
class MyMath{
public int div(int x, int y)throws Exception{ //此方法不处理异常
return x/y;
}
}
public class Test{
public static void main(String args[]){
try{
System.out.println(new MyMath().div(10,0));
}catch(Exception e){
e.printStackTrace();
}
}
}
收藏
举报
TAG: