Will using new (std::nothrow) mask exceptions thrown from a constructor?

后端 未结 3 1338
庸人自扰
庸人自扰 2020-12-20 14:00

Assume the following code:

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

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

What happens if we a

3条回答
  •  無奈伤痛
    2020-12-20 14:39

    Foo's constructor can still throw exceptions and they will fall through.

    The constructor is not called until after the memory is allocated.

提交回复
热议问题