How to use "retry" into two deep begin/rescue/end ?

How to use "retry" into two deep begin/rescue/end ?

Post by ?utf-8?q?I » Fri, 04 Apr 2008 08:27:39


Hi, in the code below I want "retry/break/XXXXX" (undefined) in SECOND BEGIN
to go back to FIRST BEGIN when "raise" instead of SECOND BEGIN but it goes to
SECOND BEGIN.

I think it's the expected behaviour but maybe there is a way to get what I
want, is it possible?


------------------------------------------------------------
class MyTcpServer < GServer

def serve(io)

loop do
begin # FIRST BEGIN
puts "welcome"
...
...
begin # SECOND BEGIN
raise
rescue
puts "ERROR"
retry/break/return/XXXXX # Restart from FIRST BEGIN (doesn't work)
end
...
...
rescue
$stderr.print "serve(io) ERROR: " + $!
end
end # loop do

end # def serve(io)
------------------------------------------------------------


Thanks a lot.


--
Iaki Baz Castillo
 
 
 

How to use "retry" into two deep begin/rescue/end ?

Post by yerme » Fri, 04 Apr 2008 08:57:35


Can you combine the two?


rescue # most other stuff

 
 
 

How to use "retry" into two deep begin/rescue/end ?

Post by UGXDsWEsIE » Fri, 04 Apr 2008 12:19:53

# your first begin is anchored on a loop, so you can use retry.

sorry typo, that should be "next" instead, as show in example :)
 
 
 

How to use "retry" into two deep begin/rescue/end ?

Post by Iki Baz Ca » Sat, 05 Apr 2008 04:35:12

El Jueves, 3 de Abril de 2008, yermej escribi >>>> rescue NameError # or whatever class of error you >a>t to
> > catch $stderr.print "serve(io) ERROR:>" > $!
>
> rescue # >os> >ther stuff
>
> > > > puts "ERROR"
> > retr>/b>e>k/return/XXXXX Restart from FIRST >
> > end end loop do

But what I want is going back to the previous/parent loop.

--
Iki Baz Castillo
 
 
 

How to use "retry" into two deep begin/rescue/end ?

Post by ?utf-8?q?I » Sat, 05 Apr 2008 04:36:20

El Jueves, 3 de Abril de 2008, Pea, Botp escribi:



Yeah !! thanks a lot, I was looking for it but I've not found that "next"
command anywhere. Thanks ;)



--
Iaki Baz Castillo