# panic: runtime error: index out of range [5] with length 3 (in goroutine)

- **ID:** `go/goroutine-panic-in-goroutine`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Goroutine accesses slice or array with out-of-bounds index, causing panic that crashes the entire program if not recovered.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0 | active | — | — |
| 1.22 | active | — | — |

## Workarounds

1. **Use recover() inside the goroutine to handle panic** (90% success)
   ```
   go func() {
    defer func() {
        if r := recover(); r != nil {
            log.Println("recovered from panic:", r)
        }
    }()
    arr := []int{1,2,3}
    fmt.Println(arr[5])
}()
   ```
2. **Always check bounds before accessing slice** (95% success)
   ```
   if idx < len(arr) {
    fmt.Println(arr[idx])
} else {
    log.Println("index out of bounds")
}
   ```

## Dead Ends

- **Ignoring panic and hoping it doesn't happen** — Panic crashes the program; cannot be ignored. (100% fail)
- **Using recover() in main goroutine only** — Recover must be called in the same goroutine that panicked; main goroutine cannot recover from child goroutine panic. (95% fail)
