会使用构造函数抛出的新(std :: nothrow)掩码异常吗? [英] Will using new (std::nothrow) mask exceptions thrown from a constructor?

查看:104
本文介绍了会使用构造函数抛出的新(std :: nothrow)掩码异常吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设以下代码:

Foo* p = new (std::nothrow) Foo();

如果我们的堆内存不足,

'p'将等于0.

'p' will equal 0 if we are out of heap memory.

如果我们 NOT 内存不足,但Foo的构造函数抛出异常怎么办?该异常是否会被新"的闲杂版本"p"设置为0来掩盖"?...还是从Foo的构造函数中抛出的异常会使它脱离函数?

What happens if we are NOT out of memory but Foo's constructor throws? Will that exception be "masked" by the nothrow version of 'new' and 'p' set to 0?... Or will the exception thrown from Foo's constructor make it out of the function?

推荐答案

不,不会. nothrow仅适用于对new的调用,不适用于构造函数.

No, it won't be. The nothrow only applies to the call to new, not to the constructor.

这篇关于会使用构造函数抛出的新(std :: nothrow)掩码异常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆