# TypeError: 'HTTPException' object is not callable

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

## Root Cause

当在Starlette或FastAPI中将HTTPException实例（而非异常类）作为依赖项或中间件传递时，框架尝试调用它，导致类型错误。

## Version Compatibility

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

## Workarounds

1. **使用Starlette的HTTPException类作为异常抛出，而非作为返回值** (95% success)
   ```
   from starlette.exceptions import HTTPException; raise HTTPException(status_code=404, detail='Not found')
   ```
2. **在依赖项中返回Response对象替代异常实例** (90% success)
   ```
   from starlette.responses import JSONResponse; return JSONResponse(status_code=404, content={'detail': 'Not found'})
   ```

## Dead Ends

- **尝试将HTTPException作为函数导入并直接调用** — HTTPException是类，不是函数，直接调用不会触发异常，但作为依赖项仍会出错。 (70% fail)
- **在依赖项中使用raise HTTPException而不是return** — 在依赖项中raise会立即中断请求，但若返回实例则仍会引发错误。 (60% fail)
