Re-raising the right exception

Batista, Facundo FBatista at uniFON.com.ar
Thu Oct 21 18:50:40 CEST 2004


[sjmaster at gmail.com]

#- I want to make a network call, and if it raises an exception, I want
#- to close the network connection before allowing the exception to
#- propagate up the stack. However, trying to close the network
#- connection might itself raise an exception, and I don't care about
#- that exception; I want to send the original exception. Apparently the
#- way to do this is:
#- 
#- try:
#-     network.command()
#- except Exception, bob:
#-     try:
#-         network.close()
#-     except:
#-         pass
#-     raise bob

Use finally:

>>> try:
          d
    finally:
	    try:
                {}[2]
          except:
                pass

Traceback (most recent call last):
  File "<pyshell#19>", line 2, in -toplevel-
    d
NameError: name 'd' is not defined
>>> 

.	Facundo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041021/baec67fb/attachment.html>


More information about the Python-list mailing list