Hacker News new | ask | show | jobs
by cv5005 41 days ago
>One need to write it manually each time in each function where some cleanup is needed.

You can structure your code to not need cleanup in every function.

The biggest problem with destructors is, how do you handle errors? close() can fail you know?

1 comments

Usually destructors can't fail. But for rare cases like with close() you can write a helper function (static method) which destroys the given object and returns an error if has one.