---
title: Do Not Throw Generic Errors
impact: MEDIUM
impactDescription: prevents ambiguous error handling
tags: error-handling, quality, python
---

## Do Not Throw Generic Errors

Raising generic `Exception` or `RuntimeError` makes it impossible for callers to catch specific issues.

**Incorrect:**
```python
if not user:
    raise Exception("User not found")
```

**Correct:**
```python
class UserNotFoundError(Exception):
    pass

if not user:
    raise UserNotFoundError("User ID 123 not found")
```
