Exception caught by value
catch statement accepts an object by
value
Description
This defect occurs
when a catch statement accepts an object by value.
Risk
If a throw statement passes an object and
the corresponding catch statement accepts the exception
by value, the object is copied to the catch statement
parameter. This copy can lead to unexpected behavior such as:
Object slicing, if the
throwstatement passes a derived class object.Undefined behavior of the exception, if the copy fails.
Fix
Catch the exception by reference or by pointer. Catching an exception by reference is recommended.
Examples
Result Information
| Group: C++ Exception |
| Language: C++ |
| Default: On for handwritten code, off for generated code |
Command-Line Syntax: EXCP_CAUGHT_BY_VALUE |
| Impact: Medium |
Version History
Introduced in R2015b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)