Recover

Verb · Development

Definitions

  1. In Go, a built-in function that regains control of a panicking goroutine. Only useful inside deferred functions. When called during a panic, recover stops the panic propagation and returns the panic value, allowing graceful error handling instead of crashing the program.

    In plain English: Go's emergency brake — when your program is about to crash from a panic, recover catches it and lets you handle the error gracefully instead.

    Example: "defer func() { if r := recover(); r != nil { log.Printf("recovered: %v", r) } }() — the Go equivalent of a safety net."

Related Terms