> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Do Not Use Bare Except

#### Sourcery suggestion id: `do-not-use-bare-except`

#### Description

Use `except: Exception` rather than bare `except`

#### Before

```python
try:
    some_important_code()
except:
    exception_handling_code()
```

#### After

```python
try:
    some_important_code()
except Exception:
    exception_handling_code()
```

#### Explanation

PEP 8
[recommends](https://peps.python.org/pep-0008/#programming-recommendations) that
we should avoid catching exceptions using a bare `except` clause.

The problem with these is that they catch `SystemExit` and `KeyboardInterrupt`
exceptions, which makes it harder to interrupt a program using
<kbd>CTRL</kbd>+<kbd>C</kbd>, and can also disguise other problems.

The PEP recommends catching `Exception`, which will catch all program errors, so
that is what Sourcery suggests. Note that this suggestion does not trigger if
the exception handler ends by raising the original exception.
