logoalt Hacker News

cv5005today at 12:55 PM1 replyview on HN

>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?


Replies

Panzerschrektoday at 1:38 PM

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.