
On 2019-07-26 19:26, Serhiy Storchaka wrote: [snip]
I propose to add "except" clause to "for" and "with" statement to catch exceptions in the code that can't be wrapped with "try ... except".
for VAR in EXPR: BLOCK except EXC: HANDLER
should be equivalent to
try: _it = iter(EXPR) except EXC: HANDLER else: while True: try: VAR = next(_it) except StopIteration: break except EXC: HANDLER break BLOCK
[snip] 1. The 'for' loop can have an 'else' clause, and so can the 'try' statement. Is there any ambiguity over its meaning? 2. In your example you have it catching the exception if EXPR or iter(EXPR) raises. Is that a good idea?