# panic：<自定义消息> [无人恢复] —— 进程以非零状态退出

- **ID:** `go/panic-in-goroutine-crashes-process`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

任何 goroutine 中未恢复的 panic 都会终止整个程序。与其他一些语言不同，Go 不会隔离 goroutine 的 panic。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.18 | active | — | — |
| 1.21 | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Add 'defer func(){ recover() }()' as the first statement inside every goroutine
   ```
2. **** (85% 成功率)
   ```
   Use errgroup and convert panics to errors via a recover wrapper around each task
   ```

## 无效尝试

- **** — Sub-goroutine panics still escape and crash the process (85% 失败率)
- **** — init runs in the main goroutine; cannot catch other goroutines (95% 失败率)
