[英].NET equivalent of Ruby's begin/rescue/else
Ruby有一個else塊,可以用於開始/救援(try / catch for .NET人員)
begin
#some code
rescue
#oh noes! Catches errors like catch blocks in .NET
else
#only executes when NO errors have occured
ensure
#always executes - just like the finally in .NET
end
else塊中的代碼只有在沒有引發錯誤的情況下才會執行。 .NET中是否有提供此功能的構造?
在.NET中,您只需在#some code
后#some code
:
try
{
// some code
// Only executes when NO errors have occurred
}
catch (Exception e)
{
// Catches errors
}
finally
{
// Always executes
}
任何異常中// some code
將防止“只執行”部分的發生,因為它會跳轉到catch
,然后finally
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.