首页 > 其他 > 详细

异常类

时间:2015-04-19 13:17:44      阅读:245      评论:0      收藏:0      [点我收藏+]

java使用try-catch语句来处理异常,将可能出现的异常操作放在try-catch语句的try部分,一旦try部分抛出异常,或调用某个可能抛出异常的方法,并且该方法跑出了异常对象,那么try部分将立刻结束执行,专项执行相应的catch部分,所以程序可以将发生异常后的处理放在catch中,try-catch语句可以有多个catch组成,分别处理发生的相应异常,



public class TryCatchFinally {



/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TryCatchFinally tcf=new TryCatchFinally();
int result=tcf.Test();
  System.out.println("result为:"+result);
System.out.println("test方法执行完毕");
}
/**
* divider();
* result();
* try-catch铺货while循环
* 每次循环,divider减一,result=result+100
* 如果:铺货异常,打印输出“捕获异常了”
* 否则:返回result
* @return
*/
public int Test(){
int divider=10;
int result=100;
try{
while(divider>-1)
{divider--;
   result+=100/divider;}
return result;
}
catch(Exception e){
System.out.println("抛出异常了");
return -1;
}
//finally(){}


}


}

异常类

原文:http://blog.csdn.net/briup_qiuqiu/article/details/45127511

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!