Created
April 9, 2011 02:48
-
-
Save googya/911059 to your computer and use it in GitHub Desktop.
Java的异常处理,可以进行多次
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ThreeException extends Exception{} | |
public class FinallyWorks { | |
static int count =0; | |
public static void main(String[] args) { | |
while(true){ //如果把try放到循环里,就建立了一个”程序继续执行之前必须要达到“的条件,同时也可以加入一个静态计数器,使之能尝试一定的次数 | |
try{ | |
if(count++==0){ | |
throw new ThreeException(); | |
} | |
System.out.println("没有异常"); | |
}catch (ThreeException e){ | |
System.out.println("thereeexception 发生了"); | |
}finally { | |
System.out.println("finally"); | |
if (count==2)break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment