Catching TCPSocket errors

C

christoph.heindl

Hi,

since i started network programming in ruby i wondered about the
differnt kind of errors raised. On the one site we have the SocketError
object, on the other site a multiplicity of Errno may occur
(Errno::ECONNREFUSED, Errno::EHOSTUNREACH, etc.)
This becomes quite inconvient to handle as my rescue block looks like
this:

rescue IOError, Errno::ECONNREFUSED, Errno::ECONNRESET,
Errno::ETIMEDOUT,
Errno::ENETUNREACH, Errno::ENOTSOCK, Errno::EHOSTUNREACH, SocketError
=> err

I still don't know if i catch all of them. Isn't there a more convient
way of catching just errors which might happen on TCPSocket?
regards,
christoph
 
N

nobu.nokada

Hi,

At Sat, 22 Jan 2005 05:01:02 +0900,
since i started network programming in ruby i wondered about the
differnt kind of errors raised. On the one site we have the SocketError
object, on the other site a multiplicity of Errno may occur
(Errno::ECONNREFUSED, Errno::EHOSTUNREACH, etc.)
This becomes quite inconvient to handle as my rescue block looks like
this:

rescue IOError, Errno::ECONNREFUSED, Errno::ECONNRESET,
Errno::ETIMEDOUT,
Errno::ENETUNREACH, Errno::ENOTSOCK, Errno::EHOSTUNREACH, SocketError
=> err

Errno::* are all subclasses of SystemCallError.

1)
rescue IOError, SystemCallError, SocketError => err

2)
ErrorsOnSocket = [IOError,
Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT,
Errno::ENETUNREACH, Errno::ENOTSOCK, Errno::EHOSTUNREACH,
SocketError]

rescue *ErrorsOnSocket => err
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top