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

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

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

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


=2D-----------------------------------------------------------
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)
=2D-----------------------------------------------------------


Thanks a lot.


=2D-=20
I=C3=B1aki Baz Castillo
 
Y

yermej

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 goesto
SECOND BEGIN.

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

Can you combine the two?
class MyTcpServer < GServer

def serve(io)

loop do
begin # FIRST BEGIN
puts "welcome"
...
...
raise
...
...
rescue NameError # or whatever class of error you want to catch
$stderr.print "serve(io) ERROR: " + $!

rescue # most other stuff
 
P

Peña, Botp

IyB5b3VyIGZpcnN0IGJlZ2luIGlzIGFuY2hvcmVkIG9uIGEgbG9vcCwgc28geW91IGNhbiB1c2Ug
cmV0cnkuDQoNCnNvcnJ5IHR5cG8sIHRoYXQgc2hvdWxkIGJlICJuZXh0IiBpbnN0ZWFkLCBhcyBz
aG93IGluIGV4YW1wbGUgOikNCg==
 
I

Iñaki Baz Castillo

El Jueves, 3 de Abril de 2008, yermej escribi=F3:
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rescue # most other stuff

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

=2D-=20
I=F1aki Baz Castillo
 
I

Iñaki Baz Castillo

El Jueves, 3 de Abril de 2008, Pe=C3=B1a, Botp escribi=C3=B3:
C:\family\ruby>cat test.rb
loop do
begin # FIRST BEGIN
puts "first welcome"

begin # SECOND BEGIN
raise "triggered ERROR in second begin"
rescue =3D>e
puts "rescuing error: "+e.message
puts "retrying to first welcome.."
sleep 1 # put this to slow down
next # this goes back to next loop
end
rescue
puts "Error in first welcome"
end
puts "this is never executed in this example :)"
end

C:\family\ruby>ruby test.rb
first welcome
rescuing error: triggered ERROR in second begin
retrying to first welcome..
first welcome


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



=2D-=20
I=C3=B1aki Baz Castillo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top