[python] using try: finally: except

David Stockwell winexpert at hotmail.com
Thu Jun 17 13:47:04 EDT 2004


In referring to my copy of the python bible, it tells me I can't use all 
three items 'try' except and finally.  I can use the t/f or t/e  
combinations though

What combination can i use if i want to catch the exception and still have a 
finally block?


This is a fictional example of  what I want....

try:
    x = 'hello'
except Exception, e:
    print "oops"
finally:
    y = 'world'
    print x," ", y

So I surmise one way to guarantee this does what I need would be to do this:

try:
    x = 'hello'
except Exception, e:
    print "oops"

y = 'world'
print x," ", y

Wouldn't that guarantee y and the print gets executed no matter what? My 
exception catches miscellaneous errors and then processing continues....  I 
suspect that wouldn't hold for a complex case where the action in the try 
block causes a fatal error of some sort....

David
-------
Tracfone: http://cellphone.duneram.com/index.html
Cam: http://www.duneram.com/cam/index.html
Tax: http://www.duneram.com/index.html

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963





More information about the Python-list mailing list