26.07.19 23:57, Guido van Rossum пише:
These are interesting ideas. It looks like you intend the except clause of the for loop to only cover the iter() and next() calls that are implicit in the for loop. You're right that it's awkward to catch exceptions there.
Right. If you want to catch an exception in the loop body you have to wrap the loop body with "try ... except". If you want to catch an exception in the loop body and the 'for' clause you have to wrap the whole "for" statement with "try ... except". No new syntax is needed for this. But if you want to catch an exception only in the 'for' clause you can't (without getting rid of the "for" statement at all).
However, I worry that when people see this syntax, they will think that the except clause is for handling exceptions in the loop body. (That's certainly what I assumed when I read just your subject line. :-)
I think people can make a mistake only when they see it for the first time. After you learn what this syntax means, you will not make this mistake the second time. The same applies to any other syntactic construction.