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

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

## Root Cause

A goroutine accesses an array or slice index that is out of bounds, causing a panic that is not recovered, crashing the entire program.

## Version Compatibility

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

## Workarounds

1. **Add a deferred recover inside the goroutine to handle panics gracefully** (90% success)
   ```
   go func() {
    defer func() {
        if r := recover(); r != nil {
            log.Printf("Recovered in goroutine: %v", r)
        }
    }()
    arr := make([]int, 5)
    arr[5] = 10 // panic here
}()
   ```
2. **Check slice bounds before accessing** (95% success)
   ```
   arr := make([]int, 5)
index := 5
if index < len(arr) {
    arr[index] = 10
} else {
    log.Println("Index out of bounds")
}
   ```

## Dead Ends

- **Adding recover in main but not in the goroutine** — Panic in goroutine is not caught by main's recover unless deferred in the goroutine itself. (80% fail)
- **Using a larger array but not fixing the index logic** — Band-aid solution; index may still go out of bounds in other cases. (70% fail)
