THROW-null
In this section:
Synopsis
Throw of NULL integer constant
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
throw(NULL) (equivalent to throw(0)) is never a throw of the null-pointer-constant, which means it can only be caught by an integer handler. This might be undesired behavior, especially if your application only has handlers for pointer-to-type exceptions. This check is identical to MISRAC++2008-15-1-2.
Coding standards
- MISRA C++ 2008 15-1-2
(Required) NULL shall not be thrown explicitly.
Code examples
The following code example fails the check and will give a warning:
typedef int int32_t;
typedef signed char char_t;
#define NULL 0
void example(void)
{
try {
throw ( NULL ); // Non-compliant
}
catch ( int32_t i ) { // NULL exception handled here
// ...
}
catch ( const char_t * ) { // Developer may expect it to be caught here
// ...
}
}
The following code example passes the check and will not give a warning about this issue:
typedef int int32_t;
typedef signed char char_t;
#define NULL 0
void example(void)
{
char_t * p = NULL;
try {
throw ( p ); // Compliant
}
catch ( int32_t i ) {
// ...
}
catch ( const char_t * ) { // Exception handled here
// ...
}
}