[Python-ideas] try-else without except or finally
Matt Joiner
anacrolix at gmail.com
Thu Nov 10 22:38:46 CET 2011
"Explicit is better than implicit." does not apply here at all. It's
already known that an uncaught exception will not be caught and the
rule was not applied there.
except:
raise
is as redundant as:
for stuff in things:
do_the_things()
else:
pass
On Fri, Nov 11, 2011 at 12:35 AM, Rob Cliffe <rob.cliffe at btinternet.com> wrote:
>
>
> On 10/11/2011 13:28, Steven D'Aprano wrote:
>>
>> Yuval Greenfield wrote:
>>
>>> "Try...else..." doesn't make any sense without the except jn my eyes. The
>>> "else" has to conjugate something.
>>
>>
>> We already have while...else and for...else blocks in Python. The
>> principle is the same:
>>
>>
>> while condition():
>> ...
>> else:
>> # Run the else block unless we exit the while block with a break.
>> ...
>>
>>
>> try:
>> ...
>> else:
>> # Run the else block unless we exit the try block with an exception.
>> ...
>> finally:
>> ...
>>
>>
>> This currently doesn't work without a pointless "except: raise" clause to
>> satisfy the compiler. I try to avoid writing pointless code.
>>
>>
>>
> "except: raise" makes it explicit that an exception is to be propogated.
> Far from being pointless it makes the code much more readable. "Explicit
> is better than implicit."
> Rob Cliffe
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
More information about the Python-ideas
mailing list