Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added a reference to ERR60-CPP

...

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 more information about object slicing, see OOP51-CPP. Do not slice derived objects. Further, if the copy constructor of the exception object throws an exception, the copy initialization of the exception-declaration object results in undefined behavior; see ERR60-CPP. Exception objects must be nothrow copy constructible for more information.

Always catch exceptions by lvalue reference unless the type is a trivial type. For reference, the C++ Standard, [basic.types], paragraph 9 [ISO/IEC 14882-2014], defines trivial types as

...

Bibliography

[ISO/IEC 14882-2014]

Subclause 3.9, "Types"
Clause 9, "Classes"
Subclause 15.1, "Throwing an Exception"
Subclause 15.3, "Handling an Exception" 

[MISRA 08]Rule 15-3-5

...