[python] using try: finally: except

Russell Blau russblau at hotmail.com
Thu Jun 17 23:07:08 CEST 2004


"David Stockwell" <winexpert at hotmail.com> wrote in message
news:mailman.30.1087503791.18066.python-list at python.org...
> 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

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

Of course, in your example it doesn't matter because the 'except' clause
doesn't stop execution from passing to the next line, but if you were doing
something more fatal in the 'except' clause then (I think) you would still
execute the 'finally' block.


-- 
I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.





More information about the Python-list mailing list