Consider this begin-rescue-ensure block:
attempts=0
begin
make_service_call()
rescue Exception
retry unless attempts>2
exit -1
ensure
attemps += 1
end
If you run that code as it is, it raises an exception because there is no function called 'make_service_call()'. So, it retries. But it would be stuck in infinite loop because the control never goes to 'ensure' because of the 'retry'. Shouldn't 'ensure' part of the block ensure that the code in it gets executed no matter what happens in 'begin' or 'rescue'?
Of course I can increment the count in 'begin' - that's not the point. I am just asking the question about 'ensure' to get some clarity.