On Jul 26, 2019, at 11:26, Serhiy Storchaka email@example.com wrote:
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
I’m pretty sure for…except has been proposed in the past, and people didn’t think it was common enough or the workaround ugly enough.
But with…except, that really is ugly to workaround. And very easy to get wrong, too. Usually, I think people either just scrap the nice context managers and use finally, or add two more layers of indentation, or, most commonly, just punt on the problem and don’t handle errors correctly.
So, I think adding with to the idea makes it a lot more compelling.