(I must have missed the 'try' suffix)

On Sun, Oct 11, 2020, 1:04 PM Wes Turner <wes.tur...@gmail.com> wrote:

> Nested exceptions indicated by a 'try' suffix added to the exception
> expression
>
> How could these (else-if and nested conditional) syntaxes be combined?
>
> On Sun, Oct 11, 2020, 12:46 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.
>>
>
_______________________________________________
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/RO5XPJ5BVXQUK3INRVGK4KEUK2MJC3CM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to