Love U Ruby
2013-Sep-12 13:41 UTC
Need suggestion how can I skip the rest par inside a loop when erro is raised
I need one suggestions from you :- Suppose I do have a code as below: until row == nil do #code1 begin #code2 <~~ which can raise an error rescue end #here I want some guard which can check,if any error occurred or not.If #error then skip below part and continue from the next row. #code3 row+=1 end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f3015a26339a38d85f0eb269793be82d%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Joel Pearson
2013-Sep-12 14:56 UTC
Re: Need suggestion how can I skip the rest par inside a loop when erro is raised
Just use error handling properly. begin #standard code rescue #only runs if an error occurred else #only runs if an error did not occur ensure #always runs at the end regardless of error level end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/617742ec47437252d66ff35c4d2ffead%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Scott Ribe
2013-Sep-12 15:21 UTC
Re: Need suggestion how can I skip the rest par inside a loop when erro is raised
On Sep 12, 2013, at 8:56 AM, Joel Pearson <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Just use error handling properly. > > begin > #standard code > rescue > #only runs if an error occurred > else > #only runs if an error did not occur > ensure > #always runs at the end regardless of error level > endIt seems to me that OP may not even understand: begin #standard code #only runs if no error earlier in this block rescue #only runs if an error occurred end #always runs as long as all exceptions are caught and none are re-thrown -- Scott Ribe scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org http://www.elevated-dev.com/ (303) 722-0567 voice -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/A0F51C7C-4BFF-466D-A14D-B1CBE1B120DC%40elevated-dev.com. For more options, visit https://groups.google.com/groups/opt_out.
Love U Ruby
2013-Sep-12 15:47 UTC
Re: Need suggestion how can I skip the rest par inside a loop when erro is raised
Joel Pearson wrote in post #1121289:> Just use error handling properly. > > begin > #standard code > rescueI am looking for the below operations,but only when error will be occured : a = (1..10) i=0 until a.size>10 next i+=1 if i<5 # this should be done on Error p a[i] i+=1 end If still I am not clear,please let me know the confusions. until val == nil #line1 #line2 #<~~ error can be generated here.If error happened I want to start from #line1 again.skipping the below code. #line3 ... end Thanks -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e9b727c1156db8475164983661ed4523%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Joel Pearson
2013-Sep-12 16:22 UTC
Re: Need suggestion how can I skip the rest par inside a loop when erro is raised
Maybe a real example would help, rather than infinite-loop pseudo-code. val = -3 until val > 2 begin val +=1 1/val rescue puts ''Error on '' + val.to_s else puts ''No Error on '' + val.to_s end puts ''Finished with '' + val.to_s end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4ca275853b8d2f25003ab6ea10ca89d0%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.