Do not catch everything
suggest changeWhile it’s often tempting to catch every Exception:
Or even everything (that includes BaseException and all its children including Exception):
try:
even_more_difficult_function()
except:
pass # do whatever needed
In most cases it’s bad practice. A bare except catches BaseException, including SystemExit and KeyboardInterrupt. MemoryError is an Exception, so except Exception catches it too. Each of those should generally be handled differently from ordinary logic errors. It also means there’s no clear understanding of what the internal code may do wrong and how to recover properly from that condition. If you’re catching every error, you won't know what error occurred or how to fix it.
This is more commonly referred to as ‘bug masking’ and should be avoided. Let your program crash instead of silently failing or even worse, failing at a deeper level of execution. (Imagine it’s a transactional system)
Usually these constructs are used at the very outer level of the program, and will log the details of the error so that the bug can be fixed, or the error can be handled more specifically.