The Most Diabolical Python Antipattern

Ian Kelly ian.g.kelly at gmail.com
Fri Jan 30 10:42:04 EST 2015


On Fri, Jan 30, 2015 at 8:30 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Ian Kelly <ian.g.kelly at gmail.com>:
>
>> The bare raise re-raises the most recent exception that is being
>> handled. The "raise e" raises that exception specifically, which is
>> not the most recent in the case of a secondary exception.
>
> Scary. That affects all finally clauses. Must remember that.
>
> The pitfall is avoided by using the "except: pass" antipattern but then
> you lose exception chaining.

Like I suggested earlier, just don't catch the inner exception at all.
The result will be both exceptions propagated, chained in the proper
order.



More information about the Python-list mailing list