Go theorytheory 0/50 · 0%
Error handling · easy

15. defer, panic and recover

Cleanup and exceptional exits.

`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.

Check your understanding

  1. 1. Deferred calls run in what order?

  2. 2. recover works only inside…