Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 938 Bytes

B112.md

File metadata and controls

38 lines (28 loc) · 938 Bytes

Pattern: A continue in the except block

Issue: -

Description

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).

Example of insecure code:

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

Example of secure code:

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

Further Reading