> On Jul 30, 2019, at 11:38 AM, Guido van Rossum <gu...@python.org> wrote: > ...
> > with connect() as stream: # connect() or __enter__() can fail. > for data in stream: # __next__() can fail > write(data) # write() can fail > > This very much looks like toy networking code to me -- real networking code > is always written in a completely different way, using different abstractions > that raise different exceptions, and I don't think it would be written in > this style even if `with` and `for` had optional `except` clauses. > (Alternatively, you can write little wrappers that turn OSError into > different exceptions so you can use a single try/except/except/except > statement to handle them all.) This is what I do: wrappers with custom exceptions. I think it gives the most readable code. But I definitely do not need this pattern very often. Eric _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/GEWDX7R54SS7KUXUWJVNLKPA6VFZHMMY/ Code of Conduct: http://python.org/psf/codeofconduct/