MISRA C++:2008 Rule 15-5-2
Where a function's declaration includes an exception-specification, the function shall only be capable of throwing exceptions of the indicated type(s)
Description
Rule Definition
Where a function's declaration includes an exception-specification, the function shall only be capable of throwing exceptions of the indicated type(s).1
Polyspace Implementation
The checker flags situations where the data type of the exception thrown does not match the exception type listed in the function specification.
For instance:
void goo ( ) throw ( Exception ) { throw 21; // Non-compliant - int is not listed }
The checker limits detection to throw
statements that are in
the body of the function. If the function calls another function, the checker does
not detect if the called function throws an exception.
The checker does not detect throw
statements inside
catch
blocks.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Check Information
Group: Exception Handling |
Category: Required |
Version History
Introduced in R2013b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.