TCPSocket and rescue

Discussion in 'Ruby' started by Mark Probert, Sep 4, 2003.

  1. Mark Probert

    Mark Probert Guest

    Hi, rubyists.

    I am trying to telnet to a large number of boxes. I have created a
    wrapper around the net/telnet. One of the methods is called 'alive?'
    that checks to see if the node can be reached prior to running up the
    Telnet.

    def alive?
    begin
    t = TCPSocket.new(@host,@port) # line= ./bsn.rb:83
    t.close
    return true
    rescue => e
    @exception = e
    return false
    end
    end

    When I run the this as part of a bigger program I get the following
    exceptions raised all pointing to the TCPSocket.new call:

    Exception `Errno::ETIMEDOUT' at ./bsn.rb:83 - Connection timed out -
    connect(2)
    Exception `Errno::ENETUNREACH' at ./bsn.rb:83 - Network is unreachable -
    connect(2)
    Exception `Errno::ENETUNREACH' at ./bsn.rb:83 - Network is unreachable -
    connect(2)
    Exception `Errno::ETIMEDOUT' at ./bsn.rb:83 - Connection timed out -
    connect(2)


    I am surprised that I am seeing these exceptions, given the open rescue
    clause.

    Any ideas?

    --
    -mark.
     
    Mark Probert, Sep 4, 2003
    #1
    1. Advertising

  2. Mark Probert

    ts Guest

    >>>>> "M" == Mark Probert <probertm@NOSPAM_acm.org> writes:

    M> def alive?
    M> begin
    M> t = TCPSocket.new(@host,@port) # line= ./bsn.rb:83
    M> t.close
    M> return true
    M> rescue => e

    you catch only StandardError, write it

    rescue Exception => e

    M> @exception = e
    M> return false
    M> end
    M> end


    Guy Decoux
     
    ts, Sep 5, 2003
    #2
    1. Advertising

  3. Mark Probert

    Mark Probert Guest

    Guy did say ...

    >
    > you catch only StandardError, write it
    >
    > rescue Exception => e
    >

    Thank you, Guy.


    -mark.
     
    Mark Probert, Sep 5, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Gundlach

    =~ and rescue

    Patrick Gundlach, Oct 19, 2003, in forum: Ruby
    Replies:
    13
    Views:
    214
    Patrick Gundlach
    Oct 23, 2003
  2. Matthew Margolis

    TCPSocket and windows

    Matthew Margolis, Mar 2, 2005, in forum: Ruby
    Replies:
    4
    Views:
    245
    Matthew Margolis
    Mar 2, 2005
  3. Eric Haase
    Replies:
    0
    Views:
    148
    Eric Haase
    Apr 22, 2006
  4. Satish Talim

    TCPSocket and RFC 821

    Satish Talim, Jul 30, 2006, in forum: Ruby
    Replies:
    9
    Views:
    163
    Yohanes Santoso
    Jul 31, 2006
  5. Zouplaz
    Replies:
    5
    Views:
    536
    Juan Matias
    Jul 4, 2007
Loading...

Share This Page