Under what circumstances are C++ destructors not going to be called?

前端 未结 8 862
-上瘾入骨i
-上瘾入骨i 2020-12-02 08:52

I know that my destructors are called on normal unwind of stack and when exceptions are thrown, but not when exit() is called.

Are there any other cases where my des

8条回答
  •  不思量自难忘°
    2020-12-02 09:28

    If a function or method has a throws specification, and throws something NOT covered by the specification, the default behavior is to exit immediately. The stack is not unwound and destructors are not called.

    POSIX signals are an operating system specific construct and have no notion of C++ object scope. Generally you can't do anything with a signal except maybe, trap it, set a global flag variable, and then handle it later on in your C++ code after the signal handler exits.

    Recent versions of GCC allow you to throw an exception from within synchronous signal handlers, which does result in the expected unwinding and destruction process. This is very operating system and compiler specific, though

提交回复
热议问题