MISRAC++2008-15-3-3 (C++ only)
In this section:
Synopsis
(Required) Handlers of a function-try-block implementation of a class constructor or destructor shall not reference non-static members from this class or its bases.
Enabled by default
Yes
Severity/Certainty
Medium/Low

Full description
One or more exception handlers in a constructor or destructor accesses a non-static member variable that might not exist. This check is identical to CATCH-xtor-bad-member, MISRAC++2023-18.3.3.
Coding standards
- MISRA C++ 2023 18.3.3
(Required) Handlers for a function-try-block of a constructor or destructor shall not refer to non-static members from their class or its bases
Code examples
The following code example fails the check and will give a warning:
int throws();
class C
{
public:
int x;
static char c;
C ( )
{
x = 0;
}
~C ( )
{
try
{
throws();
// Action that may raise an exception
}
catch ( ... )
{
if ( 0 == x ) // Non-compliant – x may not exist at this point
{
// Action dependent on value of x
}
}
}
};
The following code example passes the check and will not give a warning about this issue:
class C
{
public:
int x;
static char c;
C ( )
{
try
{
// Action that may raise an exception
}
catch ( ... )
{
if ( 0 == c )
{
// Action dependent on value of c
}
}
}
~C ( )
{
try
{
// Action that may raise an exception
}
catch (int i) {}
catch ( ... )
{
if ( 0 == c )
{
// Action dependent on value of c
}
}
}
};