Hacker News new | past | comments | ask | show | jobs | submit login

> The best solution to this problem seems to be Python's "with".

Ehhh... `with` is a crude substitute for destructors. C++ is a whole language designed around RAII. Python really is not.

You do make a good point that the handling of exceptions in destructors in C++ is problematic. But you can actually throw from destructors, as long as the destructor wasn't called during unwind for another throw. I'm of the opinion that the inability to throw again during unwind is a glaring bug in the standard, since it presumes people can know if their code is going to throw, which is like presuming people know where their bugs are. But the reasonable way to work around it is to squelch exceptions from destructors when another exception is already in-flight. This is usually fine, as the "secondary exceptions" thrown during an unwind are usually side-effects of the "primary exception" anyway.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: