Ensure clauses
Today I learned about the ensure
clause when raising exceptions. I was having trouble cleaning up certain operations, now within the ensure
block the code will always get executed whether an exception is raised or not.
def foo
begin
raise Exception, "Oh no"
ensure
return "Clean me up Scotty"
end
end
Tweet