用 try ...Catch... 把new 包起来试试。

解决方案 »

  1.   

    对,用try 和 catch
    具体:
      try
        {
          a=new int[999....999];
          if(a==NULL)
          {
          AfxMessageBox("error");
          throw"Memery allocation failed";
          }
          else delete a;
        }
      Catch(char * exception)
      {
         cout<<exception<<endl;
      }
    ..........
    另外,你申请的也太大了点吧,呵呵
              
      

  2.   

    对,用try 和 catch
    具体:
      try
        {
          a=new int[999....999];
          if(a==NULL)
          {
          AfxMessageBox("error");
          throw"Memery allocation failed";
          }
          else delete a;
        }
      Catch(char * exception)
      {
         cout<<exception<<endl;
      }
    ..........
    另外,你申请的也太大了点吧,呵呵
              
      

  3.   

    上面这几种方法永远执行不到AfxMessageBox,除非用 注册new操作符分配失败处理函数。
    看看这段代码:#include <stdio.h>
    #include <new.h>// Define a function to be called if new fails to allocate memory.
    int MyNewHandler( size_t size )
    {
        clog << "Allocation failed. Coalescing heap." << endl;    // Call a fictitious function to recover some heap space.
        return CoalesceHeap();
    }void main()
    {
        // Set the failure handler for new to be MyNewHandler.
        _set_new_handler( MyNewHandler );    int *a = new int[999999999];
    }
      

  4.   

    sorry,少打了几个字,用_set_new_handler( )函数注册new操作符分配失败处理函数。
      

  5.   

    你看看msdn中的set_new_handle就可以了
    上面见得清清楚楚,明明白白,真真切切。
    呵呵