Hacker News new | ask | show | jobs
by adamwk 1310 days ago
Does defer get called on panic? I thought panic cancels all further execution
1 comments

Yes it does, which is why recovering from a panic can be done in a deferred function. The go runtime maintains enough metadata to track what deferred functions need to be run while unwinding the stack.