--_9616f68c-8320-4a6d-a419-cee8dc772025_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
HI. Everyone. Real newbie question with throw & catch.
I am running the book example.
def promptAndGet(prompt)
print prompt
res = readline.chomp
throw :quitRequested if res == "!"
return res
end
catch :quitRequested do
name = promptAndGet("Name: ")
age = promptAndGet("Age: ")
sex = promptAndGet("Sex: ")
# ..
# process information
end
promptAndGet("Name:")When I run this and type "!" for every prompt(2) then I get the following errortemp1.rb:4:in `throw': uncaught throw `quitRequested' (NameError)
from temp1.rb:4:in `promptAndGet'
from temp1.rb:19Isn't catch supposed to run when "!" is ran?
If I don't put "!" on first prompt, I was expecting the program to end,ut the catch block runs anyway and asks
the Name at the end again.
Name: song
Age: 4
Sex: m
Name:songPlease somebody help me explain how this throw & catch flow works.
Thank you.
_________________________________________________________________
Hotmailis up to 70% faster. Now good news travels really fast.
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009-_9616f68c-8320-4a6d-a419-cee8dc772025_--