Never silence generic exceptions in code…ever

This will be short and sweet. I recently came across some code that caught a generic exception but immediately discarded it. The exception actually held valuable intel into a problem in a production environment.

Never do this:

Always log the exception even if you don’t want to “deal” with it in your code path. Swallowing exceptions is one of the biggest mistakes you can make as a developer. It prevents real problems from surfacing and is a lazy way to code. An exception is raised because there is a problem somewhere…don’t cover it up. I suggest always at least logging an exception, even when it might be an expected one (missing key in a dict, number formatting, etc…). You’ll thank me later when you have to dig through logs to find a problem.