抛弃灾难的例外 - 缺点是什么
Throwing exceptions in destructors - what are the downsides?
在破坏者中投掷异常的缺点是什么?
现在我唯一能看到的缺点是它可能会停止释放资源,还有其他缺点吗?
如果由于放松堆栈来处理另一个异常而被调用,则投掷将终止程序 - 您一次不能有一个未经治疗的例外。
如果阵列元素的驱动器会抛出,则将不会调用其余元素的破坏者。这可能导致内存泄漏和其他坏处。
投掷灾难使得很难或不可能提供例外保证。例如,用于实施分配的"复制和汇合"成语(即,如果抛出例外,没有任何更改的保证)将失败:
thing & thing::operator=(thing const & t) {
// Copy the argument. If this throws, there are no side-effects.
thing copy(t);
// Swap with this. Must have (at least) a strong guarantee
this->swap(copy);
// Now the operation is complete, so nothing else must throw.
// Destroy the copy (now the old value of "this") on return.
// If this throws, we break the guarantee.
return *this;
}
相关文章:
- 使用rdtsc进行基准测试的缺点是什么
- 将字段(在类中)定义为引用的缺点是什么?
- 嵌套向量的缺点是什么?
- 模板而不是接口的缺点是什么?(C++)
- 在C 项目中剩下未使用的类的缺点是什么?
- 在64位系统上创建一个非常大的数组的缺点是什么
- C++协方差返回类型的缺点是什么
- 在将GITHUB库包含在您的项目中之前,汇编GitHub库的优点 /缺点是什么?
- 单源项目结构的缺点是什么?
- 仅使用UDP托管小型服务器应用程序的缺点是什么
- 抛弃灾难的例外 - 缺点是什么
- 使用继承来减少重复代码的缺点是什么
- 以不同方式实现可变参数构造函数的模板类:每个版本的优点和缺点是什么
- 如果使单一实例构造函数受到保护,缺点是什么 - 继承 - C++11.
- 为C++提供标准GUI库的缺点是什么
- 如何访问类变量?公共方法/getters与继承.优点和缺点是什么
- 对所有异常使用一个基类的缺点是什么?
- 使用AVL树的缺点是什么?
- "upcasting"的缺点是什么?
- OpenGL函数在命名空间gl中的缺点是什么?