[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Catching TCPSocket errors

christoph.heindl@gmail.com

1/21/2005 7:57:00 PM

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

2 Answers

nobu.nokada

1/22/2005 1:56:00 AM

0

Hi,

At Sat, 22 Jan 2005 05:01:02 +0900,
christoph.heindl@gmail.com wrote in [ruby-talk:127579]:
> 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

--
Nobu Nakada


christoph.heindl@gmail.com

1/22/2005 11:39:00 AM

0

thanks,
that will help :)

christoph