Abuse of the object-nature of functions?
Georg Brandl
g.brandl-nospam at gmx.net
Tue Jul 11 16:15:48 EDT 2006
Ant wrote:
>> > try:
>> > # Do some stuff
>> > except Exception, err:
>> > if err not in (DontCatchMe1, DontCatchMe2):
>> > # Handle err
>> >
>> > HTH,
>> > ~Simon
>>
>> Dang! not only did somebody else beat me to it, but my code is wrong
>> and theirs correct.
>
> Ignoring the fact you haven't re-raised the exception (as we can ignore
> the fact mine doesn't handle the others ;-) ), it does show a different
> valid approach: mine has an advantage if the exceptions you don't want
> to handle inherit from a small number of base classes; yours has the
> advantage if there are a large number of unrelated exceptions that need
> ignoring.
His code is wrong since "err" is not the exception class but an instance.
"if type(err) ..." would be correct but unpythonic.
Georg
More information about the Python-list
mailing list