From: Csaba Henk <"csaba@..."@...> Date: 2006-07-22T08:20:08+09:00 Subject: Re: contine after exception On 2006-07-21, junkone@rogers.com wrote: > How do i continue a loop after a exception? It actually captures the > exception . How do i get the exception handler to start executing from > 4 to call the printstuff function? > > > def printStuff(inpu) ## just print stuff > puts "printing" + inpu.to_s > if (inpu==3) > raise RetryException.new(true) > end > # raise RuntimeError > end > def enter1 > begin > [1,2,3,4,5,6,7,8].each{|value| printStuff(value)}#call function > to print. > > > rescue RetryException > > puts " inside rescuedo nothing" > ###QUESTION: how to continue calling > #puts dd.okToRetry > > rescue > puts "other exception" > ensure > puts "insode ensire" > end > end > end Do you think of something like this? ############################################# module Exception::Continuable def try &bl bl.call rescue Exception => exp callcc do |cc| exp.instance_variable_set :@continuation, cc exp.instance_variable_set :@binding, bl class << exp attr_reader :continuation, :binding def continue @continuation.call end end raise exp end end end class Object include Exception::Continuable end class RetryException < Exception end def printStuff(inpu) ## just print stuff puts "printing" + inpu.to_s if inpu == 3 raise RetryException end end begin [1,2,3,4,5,6,7,8].each{|value| try do printStuff(value) end } rescue RetryException => err puts " inside rescuedo nothing" err.continue rescue puts "other exception" ensure puts "insode ensire" end ===========> printing1 printing2 printing3 inside rescuedo nothing printing4 printing5 printing6 printing7 printing8 insode ensire ############################################# Regards, Csaba