Ruby has an else block that would go in a begin/rescue (try/catch for .NET folks)
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
The code in the else block will only execute if no errors have been raised. Is there a construct in .NET that provides this functionality?
In .NET, you can just list the code after #some code:
try
{
// some code
// Only executes when NO errors have occurred
}
catch (Exception e)
{
// Catches errors
}
finally
{
// Always executes
}
Any exception within // some code will prevent the "Only executes" section from occurring, as it will jump to the catch then finally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With