finnally的一些用法

如下面的例public class FinallyTest {

	static int count =0;
	
	public static void main (String [] args ){
		while(true){
			try {
				if (count++ ==0){
					throw new Exception() ;
				}
				System.out.println("no exception") ;
			} catch (Exception e) {
				System.out.println("there is exception") ;
			}finally{
				System.out.println("in finnally") ;
				if (count == 2)
					break ;
			}
		}
	}
}


  可知道如何应付 Java 违例(类似 C++的违例)不允许我们恢复至违例产生地方的这一事
实。若将自己的 try 块置入一个循环内,就可建立一个条件,它必须在继续程序之前满足。亦可添加一个
static 计数器或者另一些设备,允许循环在放弃以前尝试数种不同的方法。这样一来,我们的程序可以变得
更加“健壮”。

输出为:

there is exception
in finnally
no exception
in finnally

转载于:https://www.cnblogs.com/chuiyuan/p/4343109.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值