C++ : handle resources if constructors may throw exceptions (Reference to FAQ 17.4]

后端 未结 4 639
故里飘歌
故里飘歌 2020-12-02 01:41

Thanks for all the response.

I reformatted my question to understand the state of the member pointer after the containg class constructor throws an exception

4条回答
  •  不思量自难忘°
    2020-12-02 01:51

    The question really doesn't make any sense. new Fred(); will never return NULL. It will only ever either successfully create a Fred object, or throw an exception. If it threw an exception, the Fred object would never have existed, so it's destructor would not be called.

提交回复
热议问题