title: Are there cases where using std::set_terminate does not catch a C++ pure virtual function call?
body: <p>Somewhere deep inside an executable running on a Linux server, there is a C++ pure virtual function call. It causes the server to crash, leaving no program trace data, no stack trace and no core dump. Only some log files remain. It is almost certainly caused by a lifetime issue, and I have a good idea where it is happening, but I would like proof. I have tried to remedy this situation by using <code>std::set_terminate</code> to set a handler to be run when terminate is called. This works in tests. For example, if I cause a pure virtual call, using:</p>
  
  <pre><code>class Base {
  public:
      Base() {}
      virtual ~Base(){}
      virtual void foo() = 0;
  };
  
  class Derived: public Base {
  public:
      Derived(): n_(0) {}
      ~Derived(){}
      void foo() {
              n_ = 1;
      }
  private:
      int n_;
  };              
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>Base* p = new Derived();
  Base* p1 = p;
  p-&gt;~Base();
  p1-&gt;foo();
  </code></pre>
  
  <p>the handler works and produces trace data, stack trace and core dump. The runtime system prints </p>
  
  <blockquote>
    <p>pure virtual method called</p>
  </blockquote>
  
  <p>for this test. </p>
  
  <p>There is no other call to <code>set_terminate</code> in the code. The test is done when the server is up and running, so any subsequent calls that might have gazumped my handler should have happened, if they were going to. However, in the actual server, this does <strong>not</strong> catch the pure virtual call. The only situation I can think of that might cause this is a call to set the terminate handler after mine. Are there any other ways that my terminate handler could be avoided?</p>