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

# Raise From Previous Error

#### Sourcery refactoring id: `raise-from-previous-error`

#### Description:

Suggests raising from a previously-raised exception.

#### Before:

```python
x = int(input())

try:
    print(1 / x)
except ZeroDivisionError:
    raise ValueError("Can't divide by zero")
```

#### After:

```python
x = int(input())

try:
    print(1 / x)
except ZeroDivisionError as e:
    raise ValueError("Can't divide by zero") from e
```

#### Explanation:

Exception chaining was introduced in Python 3
[PEP 3134](https://www.python.org/dev/peps/pep-3134/), and is an implicit part
of exception handling. This suggestion converts the implicit exception chain
into an explicit one, as suggested by Pylint's `raise-missing-from` error.
