MISRA C++:2008 Rule 15-1-2
NULL shall not be thrown explicitly
Description
Rule Definition
NULL shall not be thrown explicitly.1
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 | 
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.