3 ms·
Defer has nothing to do with error handling. Defer is a great feature in Go, I've never seen someone complain about it.
by Thaxll 5y ago
Defer has nothing to do with error handling. Defer is a great feature in Go, I've never seen someone complain about it.
- laserbeam 5y agoDefer CAN help with error handling, but you need other language features for that. You need well defined error types or exceptions in some way or another. Zig has errdefer which only runs if an error occurred below the statement within that scope. It allows you to always keep cleanup locally, but you can still handle errors for your business logic somewhere else. errdefer is cool, but I don't think C should support it. Mainly because you'd need to spec errors at a language level, and doing that today is probably impossible.