Go Defer Panic Recover

Guides Go's defer, panic, and recover — the LIFO ordering and arguments-evaluated-at-the-defer-statement semantics, why defer is near-free since open-coded defers (so don't avoid it except in tight loops), the loop-defer handle-leak pitfall, panic only for programmer bugs and unrecoverable states (not ordinary failure), and recover only inside a deferred function at a boundary to convert a panic into an error. Auto-invokes when writing or editing defer, panic, recover, or deferred cleanup, and on "why does this defer run in the wrong order", "should this panic", or "how do I stop a panic from crashing the process". Routes ordinary error-as-value handling to go-error-handling.

ctoth Updated

File contents

ctoth/golang-skills-plugin/tree/main/plugins/golang/skills/go-defer-panic-recover commit 1e812ff204

Frequently asked questions

npx skillmds@latest add ctoth/go-defer-panic-recover