From: Patrick Li Date: 2008-08-29T04:28:35+09:00 Subject: Subtle bug with catch/throw. Am I missing something? Hi, I'm having trouble locating this bug that I'm having. I think it's because I don't completely understand Ruby's throw/catch mechanism. I'm trying to write a simple example that demonstrates the same problem, but I can't track down the bug. Here's my code: Is there any subtleties that may cause throw/catch to not behave as expected? def idle(engine,key) catch(:exit) do <-- Catch :exit while engine.nextFrame(key) engine.drawFrame do drawInContext(@img, 0, 0, 1) end @enterEvent.listen do @state = method(:active) puts "player entered" throw :exit <-- Throw :exit end end end end Gives me: "in `throw': uncaught throw `exit' (NameError)" And what's really strange is, the problem goes away after putting in a print statement. def idle(engine,key) catch(:exit) do <-- Catch :exit while engine.nextFrame(key) engine.drawFrame do drawInContext(@img, 0, 0, 1) end @enterEvent.listen do @state = method(:active) puts "player entered" throw :exit <-- Throw :exit end end end puts "end" <-- This line causes the problem to go away. end Thanks a lot for your help. Any place to start looking would be really helpful. I'm fresh out of ideas. -Patrick I'm using Ruby 1.8.6 on Windows. -- Posted via http://www.ruby-forum.com/.