defer always executes on scope exit, errdefer executes on an error exit. In principle, this is similar to the logic of a try/catch/finally:
try { // whatever } catch { // errdefer would belong here } finally { // defer would happen here }
defer always executes on scope exit, errdefer executes on an error exit. In principle, this is similar to the logic of a try/catch/finally: