Regarding exception handling

From: Aggelos I. Orfanakos (aorfanakos_at_gmail.com)
Date: 01/30/05


Date: 30 Jan 2005 11:47:18 -0800

Hello.

In a program, I want to ensure that a socket closes (so I use try ...
finally), but I also want to catch/handle a socket exception. This is
what I have done:

try:
try:
s = ... # socket opens

# various code ...
except socket.error, x:
# exception handling
finally:
s.close() # socket closes

Is there a more "elegant" or "proper" way to do this? Or the above code
is OK?

Thanks in advance.



Relevant Pages

  • Re: Socket module bug on OpenVMS
    ... it doesn't work because it simply raises a socket exception all the time. ... then a higher layer can be built on top of that lowest level ...
    (comp.lang.python)
  • Asynchronous socket woes
    ... Using TCP socket in Stream mode. ... private void OnSend ... Add exception handling to the Receive method ...
    (microsoft.public.dotnet.languages.csharp)