Regarding exception handling
From: Aggelos I. Orfanakos (aorfanakos_at_gmail.com)
Date: 01/30/05
- Next message: Aggelos I. Orfanakos: "Re: Regarding exception handling"
- Previous message: Eric Pederson: "Re: The next Xah-lee post contest"
- Next in thread: Aggelos I. Orfanakos: "Re: Regarding exception handling"
- Reply: Aggelos I. Orfanakos: "Re: Regarding exception handling"
- Maybe reply: Fredrik Lundh: "Re: Regarding exception handling"
- Maybe reply: Bryan: "Re: Regarding exception handling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Aggelos I. Orfanakos: "Re: Regarding exception handling"
- Previous message: Eric Pederson: "Re: The next Xah-lee post contest"
- Next in thread: Aggelos I. Orfanakos: "Re: Regarding exception handling"
- Reply: Aggelos I. Orfanakos: "Re: Regarding exception handling"
- Maybe reply: Fredrik Lundh: "Re: Regarding exception handling"
- Maybe reply: Bryan: "Re: Regarding exception handling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|