MISRA C++:2008 Rule 15-3-6
Where multiple handlers are provided in a single try-catch statement or function-try-block for a derived class and some or all of its bases, the handlers shall be ordered most-derived to base class
Description
Rule Definition
Where multiple handlers are provided in a single try-catch statement or function-try-block for a derived class and some or all of its bases, the handlers shall be ordered most-derived to base class.
Rationale
In a try-catch
or function-try
block, exception
objects of a derived class match to handler catch
blocks that accept the
base class. If you place handlers of the base exception class before handlers of the derived
exception class, the base class handler handles both base and derived class exceptions. The
derived class handler becomes unreachable code, which is unexpected behavior. When using a
class hierarchy to raise exceptions, make sure that the handler of a derived class precedes
the handler of a base class.
Polyspace Implementation
Polyspace® flags a handler block if it follows a handler of a base class.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Exception Handling |
Category: Required |
Version History
Introduced in R2013b