.. _exceptions-couldusetry: .. _could-use-try: Could Use Try +++++++++++++ Some commands may raise exceptions. It is recommended to use the try/catch block to intercept those exceptions, and process them. * / : ``DivisionByZeroError`` * % : ``DivisionByZeroError`` * `intdiv() `_ : ``DivisionByZeroError``, ``ArithmeticError`` * << : ``ArithmeticError`` * >> : ``ArithmeticError`` * ``Phar\:\:mungserver`` : ``PharException`` * ``Phar\:\:webphar`` : ``PharException`` Some exceptions have an extra analysis, due to special detection condition : ``ParseError``, with eval() and ``DivisionByZeroError``. .. code-block:: php See also `Predefined Exceptions `_ and `PharException `_. Connex PHP features ------------------- + `try-catch `_ + `exception `_ + `arithmeticerror `_ + `divisionbyzeroerror `_ + `imagickexception `_ + `imagickpixelexception `_ + `invalidargumentexception `_ + `jsonexception `_ + `mysqli_sql_exception `_ + `pdoexception `_ + `pharexception `_ + `reflectionexception `_ + `svmexception `_ + `typerror `_ + `unexpectedvalueexception `_ Suggestions ___________ * Add a try/catch clause around those commands * Add a check on the values used with those operator : for example, check a dividend is not 0, or a bitshift is not negative Specs _____ +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Short name | Exceptions/CouldUseTry | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Suggestions ` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 1.5.0 | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Precision | High | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Examples | :ref:`case-mautic-exceptions-couldusetry` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Related rule | :ref:`eval()-without-try`, :ref:`check-division-by-zero` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+-------------------------------------------------------------------------------------------------------------------------+