The defer statement allows executing statements after the function has terminated.
Each executed defer statement adds a new entry to the function's deferred statements list. These entries are executed in reverse order.
To check inside defer if the function's result is a panic, call recover()
. To obtain the function's success and failure result, call recall()
. (As in a car company recalling a faulty car, not as in calling again.)
Return, fail and panic statements inside defer override the function's result.