broad-exception-caught / W0718ΒΆ

Message emitted:

Catching too general exception %s

Description:

If you use a naked ``except Exception:`` clause, you might end up catching exceptions other than the ones you expect to catch. This can hide bugs or make it harder to debug programs when unrelated errors are hidden.

Problematic code:

try:
    import platform_specific_module
except Exception:  # [broad-exception-caught]
    platform_specific_module = None

Correct code:

try:
    import platform_specific_module
except ImportError:
    platform_specific_module = None

Additional details:

For example, you're trying to import a library with required system dependencies and you catch everything instead of only import errors, you will miss the error message telling you, that your code could work if you had installed the system dependencies.

Related links:

Created by the exceptions checker.