Attempting to access a slice element using an index that is negative or greater than or equal to its length.
This panic is thrown when attempting to read or write to a slice index that is outside the slice's current length, or slicing using indices where low > high or high > capacity.
Using loops with hardcoded size boundary checks, accessing items of a nil/empty slice, or bad parsing of dynamically loaded array indexes.
1package main2 3import "fmt"4 5func main() {6 nums := []int{10, 20}7 fmt.Println(nums[5]) // Panic: runtime error: index out of range [5] with length 28}1package main2 3import "fmt"4 5func main() {6 nums := []int{10, 20}7 index := 58 9 // Fix: Always check index against slice length10 if index >= 0 && index < len(nums) {11 fmt.Println(nums[index])12 } else {13 fmt.Println("Index is out of range")14 }15}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
nums has a length of 2 (valid indices 0 and 1). Accessing nums[5] is a memory safety violation. Go detects this at runtime and panics to prevent memory reading violations.