The Most Diabolical Python Antipattern

Marko Rauhamaa marko at pacujo.net
Fri Jan 30 04:02:32 EST 2015


Mark Lawrence <breamoreboy at yahoo.co.uk>:

> On 30/01/2015 06:16, Marko Rauhamaa wrote:
>> How about:
>>
>> ==============================
>>      try:
>>          do_interesting_stuff()
>>      except ValueError:
>>          try:
>>              log_it()
>>          except:
>>              pass
>>          raise
>> ==============================
>>
>> Surprisingly this variant could raise an unexpected exception:
>>
>> ==============================
>>      try:
>>          do_interesting_stuff()
>>      except ValueError:
>>          try:
>>              log_it()
>>          finally:
>>              raise
>> ==============================
>>
>> A Python bug?
>
> It depends on the Python version that you're running - I think!!!  See
> https://www.python.org/dev/peps/pep-3134/

TL;DR

My Python did do exception chaining, but the problem is the surface
exception changes, which could throw off the whole error recovery.

So I'm thinking I might have found a valid use case for the "diabolical
antipattern."


Marko



More information about the Python-list mailing list