1、try**塊中無異常:
執行結果為:public static void main(string args) catch(exception e)finally
}
這種情況中,執行順序為try→finallytry1
finally3
2、try**塊中有異常:
執行結果為:public static void main(string args) catch(exception e)finally
}
當try中語句出現異常,執行順序就變為catch→finallycatch2
finally3
3、需要return的try/catch語句(無異常):
返回值為:3private static int trytest()catch(exception e)finally
}
只要finall中有return,就會執行finally中的return
4、需要return的try/catch語句,有輸出也有返回值(無異常):
返回值為:private static int trytest()catch(exception e)finally
}
5、需要return的try/catch語句(有異常):try
3
返回值為:3private static int trytest()catch(exception e)finally
}
一定返回finally中的return
總結:
try catch finally
try catch執行順序
staticvoidmain stringargs catch finally e catch finally 丟擲異常在 內層a,e處由外層catch塊捕獲,並執行外層finally 丟擲異常在 內層b處,且有一合適內層catch捕獲,執行內層finally,後執行e處 丟擲異常在 內層b處,但內...
try catch巢狀執行順序
try catch finally e catch finally丟擲異常在 內層a,e處由外層catch塊捕獲,並執行外層finally 丟擲異常在 內層b處,且有一合適內層catch捕獲,執行內層finally,後執行e處 丟擲異常在 內層b處,但內層catch塊沒有合適處理程式,執行內層fin...
try catch裡面try catch巢狀
try catch裡能否內嵌try catch?答案是肯定的。但是等內層try catch出異常之後是個什麼執行順序呢?看下面 static void main string args catch exception ex finally console.readkey private static...