1、try**塊中無異常:
public static void main(string args) catch(exception e)finally
}
執行結果為:
try1
finally3
這種情況中,執行順序為try→finally
2、try**塊中有異常:
public static void main(string args) catch(exception e)finally
}
執行結果為:
catch2
finally3
當try中語句出現異常,執行順序就變為catch→finally
3、需要return的try/catch語句(無異常):
private static int trytest()catch(exception e)finally
}
返回值為:3
只要finall中有return,就會執行finally中的return
4、需要return的try/catch語句,有輸出也有返回值(無異常):
private static int trytest()catch(exception e)finally
}
返回值為:
try
3
5、需要return的try/catch語句(有異常):
private static int trytest()catch(exception e)finally
}
返回值為:3
一定返回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...