← Back to archive

Stdle #87 · defer · 2026-09-01

What does this Go snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

package main
import "fmt"
func work() (status string) {
defer func() {
if r := recover(); r != nil {
status = fmt.Sprintf("fail:%v", r)
}
}()
status = "ok"
panic("crash")
}
func main() {
fmt.Println(work())
}
Defer
4 attempts left

Answer & explanation