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 |
PQL Name:
std.defects.EXCP_CAUGHT_BY_VALUE
|
Version History
Introduced in R2015b
See Also
Topics
- Interpret Polyspace Bug Finder Results in Polyspace Platform User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Polyspace Results Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)