您的位置:首页 > 编程语言 > Java开发

Try、catch和finally

2016-05-03 09:33 555 查看
public class TryCatchFinally {
public static String output ="";
public static void foo(int i){
try{
System.out.println("try");
if(i == 1){
throw new Exception();
}
}catch(Exception e){
System.out.println("catch");
output += "2";
return ;
}finally{
System.out.println("finally");
output += "3";
}
output += "4";
}

public static void main(String[] args) {
foo(0);
foo(1);
System.out.println(output);
}
}

输出为:

try

finally

try

catch

finally

3423
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Trycatch和finally java