From: Robert Dober Date: 2006-07-06T19:36:05+09:00 Subject: [Bug?] Confused exception handling in Continuation Context ------=_Part_70000_24123551.1152182162286 Content-Type: multipart/alternative; boundary="----=_Part_70001_6333120.1152182162286" ------=_Part_70001_6333120.1152182162286 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all I just went over some old Iterator code from the talk-list when I found some very strange behavior concerning Exception when using the iterator. The below code loops inside the rescue clause, as a matter of fact it loops between puts i.next and puts "No more dudes" I did not find any open bug report similar to it. I tried to isolate the behavior but could not reproduce it without the callcc stuff. I tested this with * ruby 1.8.4 (2005-12-24) [i386-cygwin] * ruby 1.8.4 (2005-12-24) [i686-linux] * ruby 1.9.0 (2006-04-21) [i486-linux] -------------------------------------------- 8< ------------------------------------------------------------------- class Iterator class Exhausted < Exception; end def initialize( enum ) @enum = enum @next = nil end def next return @next.call if @next @enum.each do |item| callcc{ |@next| return item } end # do raise Exception end # def next def reset @next = nil end end # class Iterator i = Iterator.new( %w{ Ringo John Paul George } ) begin loop do puts i.next end rescue Exception puts "No more dudes" end #i.reset puts i.next --------------------------------------------------->8-------------------------------------------- Cheers Robert ------=_Part_70001_6333120.1152182162286 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Hi all

I just went over some old Iterator code from the talk-list when I found some very strange behavior concerning Exception when
using the iterator.

The below code loops inside the rescue clause, as a matter of fact it loops between
      puts i.next
and
     puts "No more dudes"

I did not find any open bug report similar  to it.

I tried to isolate the behavior but could not reproduce it without the callcc stuff.
I tested this with
* ruby 1.8.4 (2005-12-24) [i386-cygwin]
* ruby 1.8.4 (2005-12-24) [i686-linux]
* ruby 1.9.0 (2006-04-21) [i486-linux]

-------------------------------------------- 8< -------------------------------------------------------------------

class Iterator
        class Exhausted < Exception; end
        def initialize( enum )
                @enum = enum
                @next = nil
        end

        def next
                return @ next.call if @next
                @enum.each do
                        |item|
                        callcc{ |@next|
                                return item
                        }
                end # do
                raise Exception
        end # def next

        def reset
                @next = nil
        end
end # class Iterator

i = Iterator.new( %w{ Ringo John Paul George } )
begin
        loop do
                puts i.next
        end
rescue Exception
        puts "No more dudes"
end
#i.reset
puts i.next
--------------------------------------------------->8--------------------------------------------

Cheers
Robert
------=_Part_70001_6333120.1152182162286-- ------=_Part_70000_24123551.1152182162286 Content-Type: application/x-bzip2; name=iter.tar.bz2 Content-Transfer-Encoding: base64 X-Attachment-Id: f_epaws4kx Content-Disposition: attachment; filename="iter.tar.bz2" QlpoOTFBWSZTWS2gxuAAAW//hMQwAYB6Yf+OQrFQKH/n3/4AAgAIQAHc2VbWQlCKZM1J6jG0gE0Z NGTIDQYmnlAlCaBU9MTSAaNAANNDQGgAcwCYATAACYAAmAAJIpoET1PKeU8p+qaNAAAAyAPKaiHX 1ZXEo4ASzIEjcvmB4xaLQJkVWDpASEipAZgYwZDgMwyG8/49nhW7YwH97qDUQ1lzxchCT6p0YQ8q 8V9c1WxNkS0p93GKSceGFR9T2HrZga4UqbIyWajjyacE3W785C7Rc6ARiUXnRC5PgD+xNXIxmHxq XHhPBhlvbZjSGkE38M4jg2MMGtyNJ6q60M5EdkNK6ImftrKRFXgE0YaFXooNdahnFUXcoVLaVGVU Q2q2RXhjfGrmYjUj04HixL3hvr7b01ifkKYc9+G0As5klsBGRE/aQvBIf12uaA6GK616isOfJd9l qnFQFIKpVjFoiNwPIO5Rt4FlZ21NKU0OrF9Iyphfns/IGWkyjX0WZMj4qEARqbeZsDK6SAFm/O7M 4SqQZQRoWBiCpDEmVee9eQLMVQvgmM3nMgrmaLJMcElhCPJEqMfZRCeNkQtsRRi9SlqKkg4XUFVI TNSzDSmVnSqSSFCldsEyzNjMErnLkS21KfPjkDoOavXs1aL4jRSA/xdyRThQkC2gxuA= ------=_Part_70000_24123551.1152182162286--