Skip to content

Instantly share code, notes, and snippets.

@anandtripathi5
Created February 16, 2022 21:43
Show Gist options
  • Save anandtripathi5/356ddc60180d880f7f4101173c41cc0a to your computer and use it in GitHub Desktop.
Save anandtripathi5/356ddc60180d880f7f4101173c41cc0a to your computer and use it in GitHub Desktop.
Zen of python - error should never pass silently
# 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