Why is this an issue?
This is a draft version of a MISRA C++ 202x rule proposed for public review.
MISRA Rule 15.3.2
Analysis Type: Decidable,Single Translation Unit
Slicing occurs if the exception object is of a derived class and it is caught by value as the base class, which means that information unique to
the derived class’s members is lost. Slicing does not occur when the exception is caught by reference.
Exception objects may be shared between threads, such as when an exception is thrown from
std::shared_future. In this case, catching
by const reference reduces the chance of data races.
catch ( std::runtime_error e ) // Non-compliant - slicing occurs
catch ( std::exception const & e ) // Compliant – exception object is complete
Copyright The MISRA Consortium Limited © 2023
S1044 targets the same defect as this rule but for a non-mission-critical context.
External coding guidelines