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

# Remove Redundant Exception

#### Sourcery refactoring id: `remove-redundant-exception`

#### Description

Remove redundant exceptions from an except clause.

#### Before

```python
try:
    int("not an int")
except (ValueError, Exception):
    logger.log("error")
```

#### After

```python
try:
    int("not an int")
except Exception:
    logger.log("error")
```

#### Explanation

An `except` clause handles all instances of the defined exception, incl. its
subclasses. If an exception is a subclass of another exception, it's redundant
to mention both explicitly in the except clause.

Note that:

- All built-in, non-system-exiting exceptions are derived from the `Exception`
  class.
- All user-defined exceptions should also be derived from the `Exception` class.
- It's a good practice to have a base exception class for your application
  (deriving from `Exception`) and have your more specific custom exceptions
  derive from it.

#### Related Rules

- [merge-except-handler](/reference/refactorings/python/merge-except-handler/) to merge except handlers with
  the same content
- [remove-redundant-except-handler](/reference/refactorings/python/remove-redundant-except-handler/) to
  remove unreachable `except` blocks
- [use-contextlib-suppress](/reference/refactorings/python/use-contextlib-suppress/) instead of empty
  `except` blocks
- [do-not-use-bare-except](/reference/refactorings/python/do-not-use-bare-except/) to always specify which
  errors an `except` block is handling
