Module Expr Str Import alias Import alias ImportFrom alias identifier FunctionDef arguments args NameParam defaults body If CompareEq NameLoad Str body Return Dict Str NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore AttributeLoad NameLoad attr If CompareEq Call NameLoad AttributeLoad NameLoad attr Num body If BoolOpAnd UnaryOpNot SubscriptLoad NameLoad Index Str CompareIsNot AttributeLoad NameLoad attr NameLoad CompareNotEq Call NameLoad AttributeLoad NameLoad attr Str NameLoad Str body Return If Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num AttributeLoad NameLoad attr body Return Call AttributeLoad NameLoad attr keyword AttributeLoad NameLoad attr keyword AttributeLoad NameLoad attr keyword Str decorator_list AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Str Call AttributeLoad NameLoad attr Str
N/A N/A 
=============================================
B112: Test for a continue in the except block
=============================================

Errors in Python code bases are typically communicated using ``Exceptions``.
An exception object is 'raised' in the event of an error and can be 'caught' at
a later point in the program, typically some error handling or logging action
will then be performed.

However, it is possible to catch an exception and silently ignore it while in
a loop. This is illustrated with the following example

.. code-block:: python

    while keep_going:
      try:
        do_some_stuff()
      except Exception:
        continue

This pattern is considered bad practice in general, but also represents a
potential security issue. A larger than normal volume of errors from a service
can indicate an attempt is being made to disrupt or interfere with it. Thus
errors should, at the very least, be logged.

There are rare situations where it is desirable to suppress errors, but this is
typically done with specific exception types, rather than the base Exception
class (or no type). To accommodate this, the test may be configured to ignore
'try, except, continue' where the exception is typed. For example, the
following would not generate a warning if the configuration option
``checked_typed_exception`` is set to False:

.. code-block:: python

    while keep_going:
      try:
        do_some_stuff()
      except ZeroDivisionError:
        continue

**Config Options:**

.. code-block:: yaml

    try_except_continue:
      check_typed_exception: True


:Example:

.. code-block:: none

    >> Issue: Try, Except, Continue detected.
       Severity: Low   Confidence: High
       Location: ./examples/try_except_continue.py:5
    4            a = i
    5        except:
    6            continue

.. seealso::

 - https://security.openstack.org

.. versionadded:: 1.0.0

 N/A ast N/A bandit bandit.core test_properties test gen_config N/A N/A name N/A N/A N/A N/A name try_except_continue N/A N/A N/A check_typed_exception False N/A try_except_continue N/A N/A context config N/A N/A N/A node N/A context node N/A N/A N/A len N/A node body 1 N/A N/A N/A N/A N/A config N/A check_typed_exception N/A N/A node type None N/A N/A getattr N/A node type id None Exception N/A N/A N/A N/A isinstance N/A N/A node body N/A 0 N/A ast Continue N/A N/A N/A N/A bandit Issue severity N/A bandit LOW confidence N/A bandit HIGH text Try, Except, Continue detected. N/A N/A test takes_config N/A N/A test checks ExceptHandler N/A N/A test test_id B112