如果在构造函数中引发异常会发生什么 [英] What happens if an exception is raised in constructor
本文介绍了如果在构造函数中引发异常会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在一个派生类的构造函数中抛出一个异常,是调用去清除基类的析构函数吗?
If I throw an exception in the constructor of a derived class, is the destructor called to clean up the base class?
推荐答案
然后以相反的顺序调用基类的析构函数。
The destructors of the base class(es) are then called in the reverse order.
在此之前,任何已经初始化的成员的析构函数也将被调用。
Before that, the destructors of any already initialized member will also get called.
然而,当前构造的派生类的析构函数不会被调用,因为对象的这部分将不会真正构造。
However, the destructor of the currently constructed derived-class won't get called, as this part of the object will not have been really constructed yet.
这篇关于如果在构造函数中引发异常会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文