> LçÉettçËäº Mark Probert <probertm / acm.org> > Aihe: Re: Really confused about exceptions now > > Hi .. > > On Thursday 10 February 2005 13:25, Gennady Bystritksy wrote: > > > > When you do not have explicit "return" statement in your rescue, the > > execution falls down to the end of the method and returns whatever the > > last executed statement had returned (FYI: puts() returns nil). > > > Thank you. So, a more correct version of the method is: > > def alive? > begin > t = TCPSocket.new(@host, @port) ### line 143 > return true > > rescue Errno::ETIMEDOUT > @exception = " Timed out (#{@host}:#{@port})" > rescue SocketError => e > @exception = " Socket error - #{e}" > rescue Exception => e > @exception = e > end > return false > end Just for clarity, you could restructure that one more time :) def alive? begin t = TCPSocket.new(@host, @port) ### line 143 rescue Errno::ETIMEDOUT @exception = " Timed out (#{@host}:#{@port})" false rescue SocketError => e @exception = " Socket error - #{e}" false rescue Exception => e @exception = e false # Alive! else true # Clean up ensure # Close the socket if it's open end end > However, I still have the problem that this works in my test harness and not > in my actual code at the TCPSocket() call: > > > 14:30 (kant)$ ruby test.rb > .. trying to go to Foo (Foo:10.10.10.5:foo:bar) > --> failed Foo:10.10.10.5:foo:bar > .. trying to go to Foo (Foo:10.10.10.5:foo:bar) > --> failed Foo:10.10.10.5:foo:bar > > 14:31 (kant)$ ruby healthcollect.rb -g -n eeua.txt -c flow.txt -d data > .. Running 10 commands on 2 nodes. > .. processing the nodes... (thread count=35) > .. threading now ... > .. trying to go to Foo (Foo:10.10.10.5:foo:bar) > Exception `SocketError' at ./bsn_a.rb:143 - getaddrinfo: hostname nor > servname provided, or not known > --> failed Foo:10.10.10.5:foo:bar > .. trying to go to Bar (Bar:10.10.10.6:foo:bar) > Exception `SocketError' at ./bsn_a.rb:143 - getaddrinfo: hostname nor > servname provided, or not known > --> failed Bar:10.10.10.6:foo:bar > > > I have no idea as to why the SocketError would be caught in one case and not > the other. Are you doing anything else with 't' at all? Or maybe a duplicate file you're including? You might work around it by doing BasicSocket.do_not_reverse_lookup = true? > Regards, > > -- > -mark. (probertm at acm dot org) E