A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-51.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6varmmap[string]int
7deferfunc(){
8ifr:=recover();r!=nil{
9fmt.Println("recovered:",r)
10}
11}()
12m["a"]=1
13fmt.Println(m)
14}
Maps
Answer & explanation
Console output
recovered: assignment to entry in nil map
Why
Unlike reads, writing to a nil map is a runtime error: Go panics with 'assignment to entry in nil map'. The deferred recover() intercepts that panic and prints the value, so the final fmt.Println(m) never runs. You must initialize a map with make or a literal before writing to it.