Java异常处理机制以及try-catch-finally-return执行顺序(二)

2014-11-24 12:00:07 · 作者: · 浏览: 110
sException");
return "return in catch arrayIndexOutOfBoundsException";
}catch(NullPointerException e){
System.out.println("nullPointerException");
return "return in catch";
}finally{
System.out.println("finally start try");
int[] a= {2};
for(int i=0 ; i<1;i++){//②
System.out.println(a[i]);
} www.2cto.com
System.out.println("finallyend end end");
System.out.println("finally");
//return "return of finally";
}
//return "end fuction";
}
}
①处i=1运行结果:
start try
2
try end
finally start try
2
finallyend end end
finally
return of try not finally
①处i=2运行结果:
start try
2
arrayIndexOutOfBoundsException
finally start try
2
finallyend end end
finally
return in catch arrayIndexOutOfBoundsException