Skip to content

Instantly share code, notes, and snippets.

@googya
Created April 9, 2011 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save googya/911059 to your computer and use it in GitHub Desktop.
Save googya/911059 to your computer and use it in GitHub Desktop.
Java的异常处理,可以进行多次
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