On Error resume next was the first thing I learned in my first job
TL;DR: Don't avoid exceptions. Handle Them.
- Fail Fast Principle Violation
- Catch the exception and deal with it explicitly
On early programming days, we privileged the systems running before error handling.
We have evolved.
import logging
def send_email():
print("Sending email")
raise ConnectionError("Oops")
try:
send_email()
except:
# AVOID THIS
pass
import logging
logger logging.getLogger(__name___)
try:
send_email()
except ConnectionError as exception:
logger.error("Cannot send email {exception}")
[X] Automatic
Many linters warn us on empty exception blocks
If we need to skip and ignore the exception, we should document it explicitly.
- Exceptions
Prepare to deal with the errors.
Even if you decide to do nothing, you should be explicit with this decision.
Code Smell 132 - Exception Try Too Broad
Code Smells are just my opinion.
Photo by James Best on Unsplash
Thank you @Jan Giacomelli
Optimization hinders evolution. Everything should be built top-down, except the first time. Simplicity does not precede complexity, but follows it.
Alan Perlis
Software Engineering Great Quotes
This article is part of the CodeSmell Series.