Comment pourrais-je attraper socket.error: [Errno 111] Connection refused
exception?
try:
senderSocket.send("Hello")
except ?????:
print "catch !"
En attrapant tous socket.error
exceptions, et le relancer si l'attribut errno
n'est pas égal à 111. Ou, mieux encore, utilisez errno.ECONNREFUSED
constante à la place:
import errno
from socket import error as socket_error
try:
senderSocket.send('Hello')
except socket_error as serr:
if serr.errno != errno.ECONNREFUSED:
# Not the error we are looking for, re-raise
raise serr
# connection refused
# handle here