Are destructors of automatic objects invoked when terminate is called?

Posted by nbolton on Stack Overflow See other posts from Stack Overflow or by nbolton
Published on 2010-03-13T12:38:52Z Indexed on 2010/03/13 15:45 UTC
Read the original article Hit count: 159

Filed under:
|
|
|

I'm pondering a question on Brainbench. I actually realised that I could answer my question easily by compiling the code, but it's an interesting question nonetheless, so I'll ask the question anyway and answer it myself shortly.

Take a look at this snippet:

Snippet from Brainbench

The question considers what happens when we throw from a destructor (which causes terminate() to be called). It's become clear to me by asking the question that the memory is indeed freed and the destructor is called, but, is this before or after throw is called from foo? Perhaps the issue here is that throw is used while the stack is unwinding that is the problem... Actually this is slightly confusing.

© Stack Overflow or respective owner

Related posts about brainbench

Related posts about c++