Created
February 16, 2022 21:43
-
-
Save anandtripathi5/356ddc60180d880f7f4101173c41cc0a to your computer and use it in GitHub Desktop.
Zen of python - error should never pass silently
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bad | |
try: | |
mylist = get_items() | |
exception Exception as e: | |
pass | |
return mylist | |
# Good | |
import logging | |
try: | |
mylist = get_items() | |
exception Exception as e: # Handle a particular exception class that might happen in the above code | |
logging.error(f"Exception in <some function>: {str(e)}") | |
return mylist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment