# fastapi.exceptions.HTTPException: 404 Not Found

- **ID:** `python/fastapi-http-exception-handling`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The requested resource does not exist, and the code raises an HTTPException with status code 404.

## Version Compatibility

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

## Workarounds

1. **Raise HTTPException with appropriate status code and message** (95% success)
   ```
   from fastapi import HTTPException
raise HTTPException(status_code=404, detail="Item not found")
   ```
2. **Use exception handlers for custom responses** (90% success)
   ```
   @app.exception_handler(HTTPException)
async def http_exception_handler(request, exc):
    return JSONResponse(status_code=exc.status_code, content={"error": exc.detail})
   ```

## Dead Ends

- **Returning a generic error message without raising HTTPException** — Does not properly signal the error to the client; may cause confusion. (70% fail)
- **Catching the exception and returning a 200 status** — Misrepresents the error; client thinks the request succeeded. (85% fail)
