It stood out pretty clearly to me. In my example I added an 'as err' clause
that the OP. That does make it stand out less.

I've used those nested try's myself at times. But I'm concerned the syntax
would encourage an antipattern.

Although they are not identical, it seems like this should address most
actual use cases:

try:
    might_raise_OSError()
    might_raise_ValueError()
    might_raise_other()
except OSError as err:
    pass
except ValueError:
    pass
except:
    oh_well()

On Sun, Oct 11, 2020, 1:05 PM Alex Hall <alex.moj...@gmail.com> wrote:

> On Sun, Oct 11, 2020 at 6:48 PM David Mertz <me...@gnosis.cx> wrote:
>
>> I'm not advocating for it (nor against it). But the OP proposes something
>> clear different from the example in current Python.
>>
>> On Sun, Oct 11, 2020, 12:39 PM Wes Turner
>>
>>> try:
>>>     f = open('myfile.txt')
>>>     s = f.readline()
>>>     i = int(s.strip())
>>> except OSError as err:
>>>     print("OS error: {0}".format(err))
>>> except ValueError:
>>>     print("Could not convert data to an integer.")
>>> except:
>>>     print("Unexpected error:", sys.exc_info()[0])
>>>     raise
>>> ```
>>>
>>
>> I.e.
>>
>> try:
>>     might_raise_OSError()
>> except OSError as err try:
>>     might_raise_ValueError()
>> except ValueError try:
>>     might_raise_other()
>> except:
>>     oh_well()
>>
>> The proposal is to more concisely catch exceptions raised within the
>> 'except' suites themselves.
>>
>
> But I think Wes has shown pretty clear evidence that the proposal is
> easily misinterpreted. It looks too similar to existing syntax. Something
> that's more visually distinct at a glance is required.
>
_______________________________________________
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/NJOWUSHWHBO3QWP6FL3DJBOPKCFNX5HO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to