← Back to archive

Stdle #63 · defer · 2026-08-08

What does this Go snippet output?

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

package main
import "fmt"
func safe() (err string) {
defer func() {
if recover() != nil {
err = "caught"
}
}()
panic("x")
}
func main() {
fmt.Println(safe())
}
Defer
4 attempts left

Answer & explanation