[Python-ideas] except expression

MRAB python at mrabarnett.plus.com
Wed Feb 19 03:55:22 CET 2014


On 2014-02-19 01:37, Jan Kaliszewski wrote:
> 19.02.2014 02:08, Chris Angelico wrote:
>
>> On Wed, Feb 19, 2014 at 11:11 AM, Jan Kaliszewski <zuo at chopin.edu.pl>
>> wrote:
>>> IMHO bare except is practically always a very bad practice unless
>>> the
>>> exception is immediately re-raised:
>>>
>>> try:
>>>     foo()
>>> except:
>>>     logger.exception('error:')
>>>     raise
>>>
>>> ...and AFAIK, up to now, nobody proposed any syntax that would make
>>> it
>>> possible to re-raise an exception in an except expression.
>>>
>>> Therefore I believe that bare except should *not* be allowed in
>>> except expressions at all.
>>
>> Reraising inside an expression doesn't make a huge amount of sense.
>> If
>> you want to do something and then reraise, what's the value of the
>> expression? Go statement-form and make it clearer.
>
> Exactly. That's why I believe bare except should be disallowed in the
> expression form.
>
>> But there are legit uses of broad except.
>
> Apart from immediately-re-raising, base except are practically never
> a legit use IMHO.
>
+1

On the one hand, allowing a bare except would be consistent with the
statement form.

On the other hand, without the ability to re-raise, it's just asking
for trouble, although there _is_ that "consenting adults" thing! :-)



More information about the Python-ideas mailing list