34得票9回答
何时应该使用std::nothrow?

什么情况下最合适使用std::nothrow?

18得票2回答
如何结合std::make_shared和new(std::nothrow)?

C++的new运算符有一个选项,当分配失败时可以返回一个空指针而不是抛出bad_alloc异常。Foo * pf = new(std::nothrow) Foo(1, 2, 3); 是的,我理解这只能防止新对象抛出bad_alloc异常,但它不能防止Foo构造函数抛出异常。如果你想使用shar...

17得票1回答
std::make_shared和std::make_unique有“nothrow”版本吗?

对于新操作符,我们有std::nothrow版本: std::unique_ptr<T> p = new(std::nothrow) T(); 我们是否有类似于std::make_shared或std::make_unique的东西?

7得票3回答
没有抛出异常的nothrow选项下的Operator new仍然会抛出异常。

有这样的代码: #include <iostream> int main(){ for(;;){ int* ptr = new (std::nothrow) int; if(ptr == 0){ std::cout...