[Python-ideas] Retrying EAFP without DRY

Vince vince.vinet at gmail.com
Wed Jan 25 03:53:49 CET 2012


On Tue, Jan 24, 2012 at 8:19 PM, Mike Meyer <mwm at mired.org> wrote:

> Exception handling and retrying the code that caused the exception are
> part of the same concept. There is value in being able to express that
> concept directly with a single construct.

It seems to me that combining looping and exception handling in the
same construct makes code harder to read. When you come across any
looping construct, you know immediately that the following block could
occur any number of times, depending on the line where the construct
starts. In the case of try/except/retry, it may come as a surprise that the
block can actually repeat.

Also, you would probably, in most cases, need to add additional logic
before the "retry" to ensure that you don't loop forever if the "fixup"
you apply does not prevent the exception from happening again.
This logic, instead of being tied to the loop itself, now ends up well
hidden in one or many possible exception handlers.



More information about the Python-ideas mailing list