# fastapi.HTTPException: 500 Internal Server Error: An internal error occurred

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

## Root Cause

在端点函数中抛出了未捕获的异常，FastAPI 默认返回 500 错误。

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   @app.exception_handler(Exception)
async def handle_exc(request, exc):
    return JSONResponse({'error': 'internal'}, status_code=500)
   ```
2. **** (85% success)
   ```
   try:
    ...
except ValueError:
    raise HTTPException(400, 'bad value')
   ```

## Dead Ends

- **** — 如果错误是系统性的，重试仍会失败。 (60% fail)
- **** — 关闭调试模式不会修复根本问题，只是隐藏错误信息。 (50% fail)
