本文介紹了如果我在 Try 塊中返回一個值,Finally 語句中的代碼會觸發嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在為一位朋友審查一些代碼,并說他在 try-finally 塊中使用了 return 語句.即使 try 塊的其余部分沒有觸發,Finally 部分中的代碼是否仍然觸發?
I'm reviewing some code for a friend and say that he was using a return statement inside of a try-finally block. Does the code in the Finally section still fire even though the rest of the try block doesn't?
例子:
public bool someMethod()
{
try
{
return true;
throw new Exception("test"); // doesn't seem to get executed
}
finally
{
//code in question
}
}
推薦答案
簡單回答:是的.
這篇關于如果我在 Try 塊中返回一個值,Finally 語句中的代碼會觸發嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!