From: ale@... Date: 2001-08-16T01:30:16+09:00 Subject: [ruby-talk:19800] Exception handling bug? Didn't post this to the bug database, as I'm not completely sure this is a bug. But let's see what you think about it. - Aleksi =begin Bug? Hangs if called as ruby ping_hang.rb hang Works if called as ruby ping_hang.rb Hangs or works on Linux platforms with ruby 1.6.[234] and latest (2001-08-12). =end require 'timeout' require 'socket' class Ping def initialize(host) @host = host end def ping_hangs begin s = TCPsocket.new(@host, "echo") s.close rescue # Errno::ECONNREFUSED ### Attention !! end end def ping_works begin s = TCPsocket.new(@host, "echo") s.close rescue Errno::ECONNREFUSED # rescuing econnrefused works end end end def start_pinging_hangs ponger = Ping.new("localhost") loop do ponger.ping_hangs end end def start_pinging_works ponger = Ping.new("localhost") loop do ponger.ping_works end end begin if ARGV.size > 0 && ARGV.shift == "hang" timeout(0.1) do start_pinging_hangs end else timeout(0.1) do start_pinging_works end end rescue end