#pragma hdrstop

#include <new>
//#include <new.h>
#include <limits.h>
#include <iostream.h>
#include <stdio.h>

//const std::nothrow_t std::nothrow;//maybe you need it, like compiler

//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
  int *i,*j,*k;
  i = j = k = (int *) NULL; //for delete
  try
  {
    i = new(std::nothrow) int[LONG_MAX/4-1];
    cout << "Result \"new(nothrow)\" : " << endl;
    if (i == 0)
      cout << "0 (NULL) not exception" << endl;
    else
      cout << "It is good computer" << endl;
  }
  catch(...)
  {
    cout << "Here exceptions ? - anarchie" << endl;
  }
  cout << endl;
  ///////////////////////////////////////////////
  cout << "Result \"new\" : " << endl;
  try
  {
    j = new int[LONG_MAX/4-1];
    if (i == 0)
      cout << "0 (NULL) not exception" << endl;
    else
      cout << "It is good computer" << endl;
  }
  catch(std::bad_alloc)
  {
    cout << "Exception \'bad_alloc\'" << endl;
  }
  catch(...)
  {
    cout << "Another exception" << endl;
  }
  cout << endl;
  ///////////////////////////////////////////////
  cout << "Result \"new\" with set_new_handler(0) : " << endl;
  try
  {
    /*From help C++Builder 4.0

    To retain the traditional version of new,
    which does not throw exceptions, you can use set_new_handler(0).

    */
    set_new_handler(NULL);
    k = new int[LONG_MAX/4-1];
    if (i == 0)
      cout << "0 (NULL) not exception" << endl;
    else
      cout << "It is good computer" << endl;
  }
  catch(std::bad_alloc)
  {
    cout << "Exception \'bad_alloc\'" << endl;
  }
  catch(...)
  {
    cout << "Another exception" << endl;
  }
  cout << endl << "Press enter for quit" <<endl;
  ///////////////////////////////////////////////
  getchar();
  //delete nevadi 0
  delete[] i;
  delete[] j;
  delete[] k;
  return 0;
}

