Reputation: 1
Is there a way to make a Ruby program keep executing until the program has an error? I want my loop to stop when the program returns an error. Thanks
Upvotes: 0
Views: 411
Reputation: 1874
This is another example. Will run infinite times till exception comes and also handles your exception and then exit form code.
inc = 5
while true do
begin
puts 4/inc
inc-=1
rescue Exception=> e
puts e
exit
end
end
Upvotes: 2
Reputation: 4623
A infinite loop can help?
while true do
your code
end
If your code throw an error the loop stops.
Upvotes: 2