C++: Throwing an exception invokes the copy constructor?

后端 未结 6 1121
半阙折子戏
半阙折子戏 2021-01-07 14:02

We have an custom error class that is used whenever we throw an exception:

class AFX_CLASS_EXPORT CCLAError : public CObject

It has the fol

6条回答
  •  礼貌的吻别
    2021-01-07 14:56

    However, I do not understand why re-throwing a caught exception would invoke the copy constructor.

    It doesn't, but re-throwing the thrown exception is done with throw;. When you do throw e; you are requesting to throw a copy of the caught exception.

提交回复
热议问题