`defer` schedules a call to run when the function returns, ideal for closing files and unlocking mutexes; deferred calls run last-in-first-out with arguments evaluated immediately. panic unwinds the stack and recover, only useful inside a deferred function, stops it — reserve both for truly exceptional cases.
← Go theorytheory 0/50 · 0%
Error handling · easy
15. defer, panic and recover
Cleanup and exceptional exits.
Check your understanding
1. Deferred calls run in what order?
2. recover works only inside…