What about try:except:finally
Richard Gruet
rgruet at ina.fr
Fri Jul 7 12:13:40 EDT 2000
Thomas Weholt wrote:
> Hi,
>
> Does python support, or if not, would it be cool to have support for :
>
> try:
> # some code
> except :
> # catch exception
> finally:
> # clean up whatever
>
> Thomas
no, these are 2 separate constructs that you can embed:
try:
try:
# some code
except:
# catch exception
finally:
# clean-up whatever
Your proposition makes sense but it's little gain, and with separate
constructs you can do a lot of different things in the SAME try/finally,
e.g:
# Allocate resource (eg. open file)
try:
# do something
try:
# some code
except:
# catch exception
# do something else
try:
# some code
except:
# catch exception
finally:
# release resource (eg close file)
Cheers,
Richard
More information about the Python-list
mailing list