"Aggelos I. Orfanakos" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Good point, but with your way, if "s = ... # socket opens" fails, then
> nothing will catch it. What I usually do is what I wrote above (place
> it below the 2nd try), and when attempting to close it, first use an if
> like: "if locals().has_key('s'):".
Then how about:
try:
s = ... # socket opens
try:
# various code ...
finally:
s.close() # socket closes
except socket.error, x:
# exception handling
This handles all the socket exceptions in one shot. The only problem is
that different problems may have to be handled differently. For instance,
you may need to handle a transmission that failed in the middle differently
than a failure to open the socket.
Dan
--
http://mail.python.org/mailman/listinfo/python-list