try/catch/finally语句的执行顺序大概分为以下几种情况:
1、try代码块中无异常:
public static void main(String[] args) {
try{
System.out.println("try"+"1");
}catch(Exception e){
System.out.println("catch"+"2");
}finally {
System.out.println("finally"+"3");
}
}
执行结果为:
try1
finally3
这种情况中,执行顺序为try→finally
2、try代码块中有异常:
public static void main(String[] args) {
try{
//异常
Map<String,Map> map = null;
map.put("1",new HashMap());
System.out.println("try"+"1");
}catch(Exception e){
System.out.println("catch"+"2");
}finally {
System.out.println("