www.digitalmars.com         C & C++   DMDScript  

c++ - [bug] throwing exception in destructor

If an exception is thrown in a destructor, the destructors of subobjects
aren't called, the expected output from the following test-case is:

A::A
A::A
throw 0
A::~A
A::~A
caught

but with DMC 8.44.6n I get:

A::A
A::A
throw 0
caught


test-case:

#include <stdio.h>

struct A
{
  A()
  {
    printf("A::A\n");
  }

  ~A()
  {
    printf("A::~A\n");
  }
};

struct B : A
{
  A a;

  ~B()
  {
    printf("throw 0\n");
    throw 0;
  }
};


int main()
{
  try
  {
    B b;
  }
  catch (const int &)
  {
    printf("caught\n");
  }

  return 0;
}


bye, Christof

-- 
http://cmeerw.org
mailto:cmeerw at web.de                       xmpp:cmeerw at cmeerw.org

...and what have you contributed to the Net?
Aug 06 2005