user1395213
user1395213

Reputation: 1

Run Ruby program until error

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

Answers (2)

rohitkadam19
rohitkadam19

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

Tiago Peczenyj
Tiago Peczenyj

Reputation: 4623

A infinite loop can help?

while true do
    your code
end

If your code throw an error the loop stops.

Upvotes: 2

Related Questions