Why not allow empty code blocks?

Antoon Pardon antoon.pardon at rece.vub.ac.be
Fri Jul 29 09:55:07 EDT 2016


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.

-- 
Antoon Pardon




More information about the Python-list mailing list