# starlette.exceptions.HTTPException: 404: Not Found

- **ID:** `python/starlette-http-exception-status-code`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A route or dependency explicitly raised HTTPException(404) or a router matched no path, and the exception was not handled by a custom handler.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 0.37.x | active | — | — |
| 0.40.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   @app.exception_handler(HTTPException)
async def handler(request, exc):
    return JSONResponse({'detail': exc.detail}, status_code=exc.status_code)
   ```
2. **** (90% success)
   ```
   Register the handler on the specific router or app instance used in tests, not on a different app object.
   ```

## Dead Ends

- **** — HTTPException is handled by Starlette's HTTPException handler before generic Exception; order matters and generic handler may not fire. (80% fail)
- **** — Duplicates logic across every route and bypasses OpenAPI error docs. (70% fail)
