.. _structures-emptytrycatch: .. _empty-try-catch: Empty Try Catch +++++++++++++++ The code does try, then catch errors but do no act upon the `error `_. At worst, the `error `_ should be logged, so as to measure the actual usage of the catch expression. ``catch( `Exception `_ $e)`` (PHP 5) or ``catch(`Throwable `_.php>`_ $e)`` with empty catch block should be banned. They ignore any `error `_ and proceed as if nothing happened. At worst, the event should be logged for future analysis. .. code-block:: php See also `Empty Catch Clause `_. Connex PHP features ------------------- + `try `_ Suggestions ___________ * Add some logging in the catch * Add a comment to mention why the catch is empty * Change the exception, chain it and throw again Specs _____ +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Short name | Structures/EmptyTryCatch | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze ` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 0.8.4 | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Precision | Very high | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Examples | :ref:`case-livezilla-structures-emptytrycatch`, :ref:`case-mautic-structures-emptytrycatch` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+-------------------------------------------------------------------------------------------------------------------------+