Thomas R Alexander

Manager, Developer, and professional problem solver

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.

Leave a Reply

Your email address will not be published. Required fields are marked *.

You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">