AUTOSAR C++14 Rule M15-1-2
NULL shall not be thrown explicitly
Description
Rule Definition
NULL shall not be thrown explicitly.
Rationale
The macro NULL is commonly used to refer to null pointers. Compliers
interpret NULL as an integer with value zero, instead of a pointer. When
you use NULL explicitly in a throw statement, you
might expect the statement to raise a pointer type exception. The
throw(NULL) is equivalent to throw(0) and raises an
integer exception. This behavior might be contrary to developer expectation and might result
in bugs that are difficult to find. Avoid using NULL explicitly in a
throw statement.
Polyspace Implementation
Polyspace® flags a throw statement that raises a
NULL explicitly. Polyspace does not flag the statement when
NULL is raised after casting to a specific type or assigning it to a
pointer type.
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, Automated |
Version History
Introduced in R2019a