...
Because the variable declared by the exception-declaration is copy-initialized, it is possible to slice the exception object as part of the copy operation, losing valuable exception information and leading to incorrect error recovery. For instance, all exception types provided by the Standard Template Library inherit from std::exception
, which has a virtual member function, what()
, that returns implementation-defined information about the exception object. If the exception variable declared by the catch handler was sliced from the exception object created by the throw expression, calling what()
on the catch handler exception variable would not result in calling what()
on the exception object. For For more information about object slicing, see OOP51-CPP. Do not slice derived objects.
...