在派生类构造函数中抛出异常.为什么要调用基类析构函数而不是派生类析构函数?

san*_*ank 2 c++ inheritance exception

#include <iostream>
class A
{
    public:
    A() 
    {   
        std::cout << "A()" << std::endl;
    }   

 virtual  ~A()
    {   
        std::cout << "~A()" << std::endl;
    }   
};

class B:public A
{
    public:
    B() 
    {   
        throw std::exception();
        std::cout << "B()" << std::endl;
    }   

   ~B()
    {   
        std::cout << "~B()" << std::endl;
    }   
};


int main()
{
    try 
    {   
        B b;
    }   
    catch(std::exception & e)  
    {   
    }   
    return 0;
}   
Run Code Online (Sandbox Code Playgroud)

上面的代码输出,

A()
~A()
Run Code Online (Sandbox Code Playgroud)

抛出异常时,已创建B.那么为什么B的析构函数不被称为?

Car*_*ton 5

在构造函数返回之前,该对象不被视为完全构造,并且不会在不完整的对象上调用析构函数.