<div dir="ltr">And I'll never approve syntax to make it easier to just ignore all exceptions without looking at them.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 12, 2017 at 12:48 AM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, Dec 12, 2017 at 7:39 PM, Michel Desmoulin<br>
<<a href="mailto:desmoulinmichel@gmail.com">desmoulinmichel@gmail.com</a>> wrote:<br>
><br>
><br>
> Le 29/11/2017 à 19:02, Barry Warsaw a écrit :<br>
>> On Nov 29, 2017, at 12:40, David Mertz <<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a>> wrote:<br>
>><br>
>>> I think some syntax could be possible to only "catch" some exceptions and let others propagate.  Maybe:<br>
>>><br>
>>>    val = name.strip()[4:].upper() except (AttributeError, KeyError): -1<br>
>>><br>
>>> I don't really like throwing a colon in an expression though.  Perhaps some other word or symbol could work instead.  How does this read:<br>
>>><br>
>>>    val = name.strip()[4:].upper() except -1 in (AttributeError, KeyError)<br>
>><br>
>> I don’t know whether I like any of this <wink> but I think a more natural spelling would be:<br>
>><br>
>>    val = name.strip()[4:].upper() except (AttributeError, KeyError) as -1<br>
>><br>
>> which could devolve into:<br>
>><br>
>>    val = name.strip()[4:].upper() except KeyError as -1<br>
>><br>
>> or:<br>
>><br>
>>    val = name.strip()[4:].upper() except KeyError # Implicit `as None`<br>
>><br>
>> I would *not* add any spelling for an explicit bare-except equivalent.  You would have to write:<br>
>><br>
>>    val = name.strip()[4:].upper() except Exception as -1<br>
>><br>
>> Cheers,<br>
>> -Barry<br>
>><br>
><br>
> I really like this one. It's way more general. I can see a use for<br>
> IndexError as well (lists don't have the dict.get() method).<br>
><br>
> Also I would prefer not to use "as" this way. In the context of an<br>
> exception, "as" already binds the exception to a variable so it's confusing.<br>
><br>
> What about:<br>
><br>
><br>
> val = name.strip()[4:].upper() except Exception: -1<br>
<br>
</span>That happens to be the exact syntax recommended by PEP 463 (modulo<br>
some distinguishing parentheses).<br>
<br>
<a href="https://www.python.org/dev/peps/pep-0463/" rel="noreferrer" target="_blank">https://www.python.org/dev/<wbr>peps/pep-0463/</a><br>
<br>
ChrisA<br>
<div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>guido%40python.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>