【发布时间】:2013-02-01 00:48:49
【问题描述】:
Ruby 有一个 else 块,可以进入 begin/rescue(.NET 人员的 try/catch)
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 中是否有提供此功能的构造?
【问题讨论】:
-
让我想起了
On Error Move Next -
嵌套
try/catch怎么样? -
我正在寻找开箱即用的东西,而无需构建任何东西。我可以通过一个方面轻松做到这一点,但我想知道是否有关键字。
-
else 块中的代码在#some 代码之后怎么样?如果#some code
#only executes when NO errors have occured中没有异常将执行。