Try, except...retry?

Georgy Pruss SEE_AT_THE_END at
Thu Nov 13 07:07:13 CET 2003

"Isaac To" <kkto at> wrote in message news:7iptfxlywi.fsf at
| <...> The primary advantage of
| exceptions, rather than other error reporting mechanisms like a return
| value, is that you can group a lot of statements and have a single block of
| code handling all of those.  This way you can separate the error handling
| code and the normal code, to make the whole logic clearer.  <...>
| Regards,
| Isaac.

Not only that simple. I would say not only a lot of statements, but a lot of
very complex code, which however has no slightest idea what to do with
error situations inside it and how to proceess the errors or where and how
report them. E.g. it's quite often that you have open(file,mode) at the very
low level of your function hierarchy, but it's only several levels up that you
can analyze the error and decide what to do about it and pop up a message
box with something like "Error in installation; Please reinstall the program"
and log this error, instead of printing "Can't open /usr/bin/blah/blah/"
right across the screen, or having each and every function to return error
code together with some 'useful' data.

That is, I agree with you. Just wanted to add that it's not a simple trick to
process errors for a few statements in one place, but an important design

Regarding 'retry' - it's good that there's no 'retry' in Python. It would have
introduced another loop-like structure in the language. Anyway now you can
mimic it with try-except within a loop.

Georgy Pruss
u='u=;print u[:2]+chr(39)+u+chr(39)+u[2:]';print u[:2]+chr(39)+u+chr(39)+u[2:]

More information about the Python-list mailing list