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