Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.CTOR.TRY.NON_STATIC

Function try/catch block of constructor or destructor references non-static members.

MISRA-C++ Rule 15-3-3 (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.

[Undefined 15.3(10)]

Rationale

The effect of accessing a non-static member of a class or a base class in the handler (i.e. the catch part) of a function-try-block of a class constructor/destructor is undefined.

For example, if a memory allocation exception is thrown during creation of the object, the object will not exist when the handler attempts to access its members. Conversely, in the destructor, the object may have been successfully destroyed before the exception is handled, so again will not be available to the handler.

By contrast, the lifetime of a static member is greater than that of the object itself, so the static member is guaranteed to exist when the handler accesses it.

Example

class C
{
public:
   int32_t x;

   C ( )
      try
      {
         // 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
         }
      }
   ~C ( )
      try
      {
         // 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
         }
      }
};