== Why is this an issue?

When a constructor/destructor has a function-try-block, the code inside of the catch clause will be executed after the object has been destroyed (if the object was partially constructed when the exception was thrown, this part will be destroyed before going in the catch block). Therefore, the members of the object are not available, and it is undefined behavior to access them.


Since the lifetime of a static member is greater than that of the object itself, so a static member can be accessed from the catch code.


=== Noncompliant code example

[source,cpp]
----
class A {
public:
  int i;
  A ( ) try {
    // Action that might raise an exception
  } catch ( ... ) {
    if ( i == 0 ) { // Noncompliant, i has been destroyed
      // ...
    }
  }
  ~A ( ) try {
    // Action that might raise an exception
  } catch ( ... ) {
    if ( i == 0 ) { // Noncompliant
      // ...
    }
  }
};
----


== Resources

* MISRA {cpp}:2008, 15-3-3
* https://wiki.sei.cmu.edu/confluence/x/_3s-BQ[CERT, ERR53-CPP.] - Do not reference base classes or class data members in a constructor or destructor function-try-block handler



ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Remove this access to non-static member "xxx".


'''
== Comments And Links
(visible only on this page)

=== on 14 Oct 2014, 16:35:13 Ann Campbell wrote:
\[~samuel.mercier], 

* Add a See section to the description listing the appropriate MISRA number
* Fill in Applicability. Almost always this is both Sources and Tests
* Make sure the appropriate MISRA C and MISRA {cpp} fields on the references tab are filled in
* it's h2. not .h2 :-)

endif::env-github,rspecator-view[]
