The usage details of try-catch-finally

第一种形式:
try{
    ......
    ......
}catch (Exception ex){
    ......
    ......
   
}finally {
    ......
    ......
}

第二种形式:
try{
    ......
    ......
}catch (Exception ex){
    ......
    ......
}

第三种形式:
try{
    ......
    ......
}finally {
    ......
    ......
}

in conclusion:

try-catch-finally的使用细节:
先执行try代码块中代码当遇到抛出异常时,异常会被catch代码块捕获,进入catch代码,
   catch代码中如果遇到return或者手动或自动抛出异常时,
   会先执行finally代码块中的代码。
   然后再执行catch代码中如果遇到return或者手动或自动抛出异常的代码。
   如果finally代码块中的也存在return语句手动或自动抛出异常的代码。那就不再执行catch中的代码了。
try中代码正常执行,在遇到return语句时,会先执行finally中的代码,
   如果finally代码块中遇到return语句,那么程序就返回finally代码块中也有return语句的结果。
   如果finally代码块中没有遇到return语句,那么程序就返回try中的return语句的结果。

Guess you like

Origin blog.csdn.net/adminstate/article/details/131192519