#errdefer vs defer, do I need both?

1 messages · Page 1 of 1 (latest)

weary grotto
#

Will defer dealloc this on error or do I need both defer and errdefer?

short jay
#

You don't need both. defer is called at any return site of the enclosing function. errdefer is called if the enclosing function returns an error.

Note, neither will be called in cases like panics, segfaults, or signals. Panics and signals can be caught separately using handlers, which I can elaborate on a little if you're curious.

autumn thorn
#

Well, I am a little curious how those can be handled. I know about root.panic as a panic handler but is there a way to 'survive' a panic with a unwind handler?

outer owl
#

you'll probably want to dig deep into the source code, langref recommends:

See std.debug.simple_panic for a basic implementation of this namespace.