A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-113.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6varmmap[string]int
7deferfunc(){
8fmt.Println("err:",recover()!=nil)
9}()
10delete(m,"k")
11fmt.Println("deleted ok")
12m["k"]=1
13}
Maps
Answer & explanation
Console output
deleted ok
err: true
Why
delete on a nil map is a defined no-op, so it does not panic and "deleted ok" prints. The subsequent write m["k"] = 1 to the nil map panics; the deferred function recovers it, and recover() != nil is true. This contrasts the safe operations on nil maps (read, len, delete) with the one that panics (write).