My code contains a regular try-except block. I downloaded the pycodestyle library to test pep8 on my code. I tested my code and I got the following PEP8 error:
E722 do not use bare 'except'
Why does this happen, and how can I fix it? Thanks.
Deprecated use of [pep8] section name in favor of [pycodestyle] ; #591. Report E722 when bare except clause is used; #579.
When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause. A bare except: clause will catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems.
PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code. It was written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan. The primary focus of PEP 8 is to improve the readability and consistency of Python code.
You should include a specific exception.
For example,
try:
<stuff>
except IndexError:
<stuff>
Instead of
try:
<stuff>
except:
<stuff>
It helps with debugging - you'll know if an unexpected error pops up, and the error won't fly by possibly messing something else up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With