From: "Jesús Gabriel y Galán" Date: 2008-10-31T01:58:53+09:00 Subject: Re: Exceptions & loops On Thu, Oct 30, 2008 at 4:54 PM, Daniel Malcolm Webb [dbw] wrote: > I've had a look for exception in here but nothing quite does the job. > > (10264..10300).each do |i| > ... > > begin > question_text = res_q[0][1].gsub('"', "'") > rescue Exception=>g > end > > ... > End > > If this query throws and exception is there a way of aborting the > current loop i.e. the loop for record #10267 but then loop again for > #10268? > At the moment it just comes out of > question_text = res_q[0][1].gsub('"', "'") > and goes onto the next operation within the loop, which is fantastic, > but not quite what I want You want the "next" keyword, which directly jumps to the next iteration in the loop. Take a look also at break, redo and retry for other cases. irb(main):001:0> %w{a b c d e}.each do |w| irb(main):002:1* next if w=="c" irb(main):003:1> puts w irb(main):004:1> end a b d e Jesus.