Is the destructor called if the constructor throws an exception?

前端 未结 8 981
不知归路
不知归路 2020-11-29 06:57

Looking for an answer for C# and C++. (in C#, replace \'destructor\' with \'finalizer\')

8条回答
  •  佛祖请我去吃肉
    2020-11-29 07:31

    C++ -

    Nope. Destructor is not called for partially constructed objects. A Caveat: The destructor will be called for its member objects which are completely constructed. (Includes automatic objects, and native types)

    BTW - What you're really looking for is called "Stack Unwinding"

提交回复
热议问题