MISRA C++:2008 Rule 15-0-2
An exception object should not have pointer type
Description
Rule Definition
An exception object should not have pointer type.1
Rationale
If your throw expression is a pointer to a dynamically allocated
        object, the deallocation point of the allocated resource becomes ambiguous. Such ambiguity
        might lead to a memory leak. Throwing pointers as exceptions might allow functions to access
        objects after their lifetime ends, which results in an undefined behavior.
Avoid using pointers as exceptions. Throw exceptions by value or by reference instead.
Polyspace Implementation
The checker raises a violation if a
                                                  throw statement throws an
                                                  exception of pointer type.
The checker does not raise a violation if a NULL pointer is thrown as exception. Throwing a
                                                  NULL pointer is forbidden by MISRA C++:2008 Rule
                                                  15-1-2.
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: Advisory | 
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.