Skip to content

Files

Latest commit

 

History

History
25 lines (18 loc) · 584 Bytes

broad-exception-caught.md

File metadata and controls

25 lines (18 loc) · 584 Bytes

Pattern: Broad exception caught

Issue: -

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.

Example of incorrect code:

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

Example of correct code:

try:
    import platform_specific_module
except ImportError:
    platform_specific_module = None