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
The type of the object thrown must be copyable because the throw
expression may make a copy of its argument (the copy may be elided or in C++11 a move may take place instead, but the copy constructor must still be accessible and callable).
Rethrowing the exception using throw;
will not create any copies. Throwing the caught exception object using throw e;
will cause a copy of e
to be made. This is not the same as rethrowing the exception.
Your "updated" code does not work as you expect. catch (CCLAError&)
will not catch an exception of type CCLAError*
, which is the type of the exception thrown by throw new CCLAError(...);
. You would need to catch CCLAError*
. Do not do this, though. Throw exceptions by value and catch by reference. All exception types should be copyable.