#pragma hdrstop
#include <condefs.h>
#include <iostream.h>
#include <stdio.h>

//use this in C-Builder version 3
//#define CBUILDER_VER_3

//---------------------------------------------------------------------------
class EMyObject{
public:
   char ch[50];
   //construktor
   EMyObject()
   {
     strcpy(ch, "ORGINAL");
     cout << "CONSTRUCTOR of " << ch << endl;
   };
   //copy construktor
   EMyObject(EMyObject &e)
   {
     strcpy(ch, "COPY");
     cout << "CONSTRUCTOR of "<< ch << endl;
   };
   //destruktor
   ~EMyObject()
   {
     cout<< "DESTRUCTOR of " << ch << endl;
   };
};


#pragma argsused
int main(int argc, char* argv[])
{
  try
  {
    cout<< "Call exception" << endl;
    throw EMyObject();
  }
  catch(EMyObject &e)//use catch(...) in CBuilder ver. 3 = you can not release memory
  {
    //place for code working with exception is here

    #ifdef CBUILDER_VER_3
      //in C-Builder version 3 you have to free memory yourself
      ///////////////////////////////////////////////////////
      cout<< "Call delete of exception myself" << endl;
      delete &e;//in C-Builder version 4 DO NOT CALL this//
      ///////////////////////////////////////////////////////
    #endif
  }
  #ifndef CBUILDER_VER_3
    cout << endl << "WHERE IS DESTRUCTOR of COPY ???!!!! ---- Memory is not released" << endl;
  #endif
  cout << endl << "press enter for quit" << endl;
  getchar();
  return 0;
}

