# RuntimeError: Multiple exception handlers registered for the same exception type.

- **ID:** `python/starlette-runtime-error-multiple-exception-handlers`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Two or more exception handlers are added for the same exception class (e.g., HTTPException).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **Consolidate handlers into one** (90% success)
   ```
   from starlette.exceptions import HTTPException
from starlette.responses import JSONResponse
async def custom_handler(request, exc):
    return JSONResponse({'error': str(exc.detail)}, status_code=exc.status_code)
app.add_exception_handler(HTTPException, custom_handler)
   ```
2. **Use middleware instead of multiple handlers** (85% success)
   ```
   from starlette.middleware.base import BaseHTTPMiddleware
class ErrorMiddleware(BaseHTTPMiddleware):
    async def dispatch(self, request, call_next):
        try:
            response = await call_next(request)
        except HTTPException as exc:
            return JSONResponse({'error': exc.detail}, status_code=exc.status_code)
        return response
   ```

## Dead Ends

- **Removing all handlers and adding only one** — May lose custom error responses. (50% fail)
- **Using different exception classes** — Doesn't solve duplicate registration. (60% fail)
