Why not allow empty code blocks?

Antoon Pardon antoon.pardon at rece.vub.ac.be
Fri Jul 29 14:32:58 EDT 2016


Op 29-07-16 om 16:38 schreef Steven D'Aprano:
> On Fri, 29 Jul 2016 11:55 pm, Antoon Pardon wrote:
> 
>> Op 29-07-16 om 15:43 schreef Steven D'Aprano:
>>> Of course it won't, which is why I don't believe all these folks who
>>> claim that they regularly ("all the time", "fairly often") replace except
>>> blocks with `pass`. I call shenanigans -- perhaps you do it
>>> *occasionally*, but as a general rule, you can rarely replace the
>>> exception handler with a do-nothing clause and expect your code to work:
>>>
>>> try:
>>>     block
>>> except SomeException:
>>>     handle error
>>> process
>>>
>>> If you remove the error handling block, replacing it with `pass`, in
>>> general your code will just break again as soon as it continues
>>> processing.
>>
>> I think the case where you just want to ignore the exception, but it can
>> at times be useful to get some extra logging information for debuging
>> purposes, is not that rare as you seem to suggest.
> 
> I think I can count the number of times I've wanted to ignore an exception
> on the fingers of one hand. And when I did, there was no need to debug it,
> because I only ignore expected failures. There's nothing to debug.

You really should stop, generalising your own situation.

> But even if you do it all the time, how do you "get some extra logging
> information" by replacing the "except" block with `pass`? If you replaced
> the "except" block with a call to the logger, that would be one thing.
> But "pass", that won't do the job.

You don't seem to understand. There is no real except block to be replaced
by pass. There is sometime an except block added (or uncommented) to get
logging information.

-- 
Antoon Pardon.




More information about the Python-list mailing list