NOTE

panic and recover

Panic unwinding, deferred cleanup, recovery boundaries, and when not to use panic.

GoCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

panic starts stack unwinding in the current goroutine while deferred calls execute. A deferred function can call recover to intercept an active panic in the appropriate context.

Use recovery at deliberate process/request/task boundaries to log and contain unexpected failures. Do not use panic/recover as normal exception-style control flow for expected errors, and remember that recovery in one goroutine cannot directly catch a panic in another.

Loading helpful count