2 ms·
Defer 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
by laserbeam 5y ago
Defer 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.