strm = NULL;
    try
    {
        strm = new char[20];
        if (strm == NULL)
            return false;
    }
    catch(...)
    {
        if (strm != NULL)
           delete strm;
        return false;
    }在上面的语句中,当strm分配错误时,是会strm = null ? 还是会出错,跳到catch(...)下面的语句中执行?

解决方案 »

  1.   

    还真不懂,呵呵.
    而且... 要测试都难啊.不过,按照常理,如果一个操作执行错误了,就不应该产生任何效果.
    所以,strm分配错误后,它应该是NULL.
      

  2.   

    If you use the placement new form of the new operator, the form with arguments in addition to the size of the allocation, the compiler does not support a placement form of the delete operator if the constructor throws an exception.
      

  3.   

    楼上的朋友的回答考虑的是delete,我并没有delete
     
    up !
      

  4.   

    你可以catch到内存不够的情况。
    当然,其他情况要看new的实现了,抛出Exception的地方肯定会被你的catch捕获到。
      

  5.   

    按照楼上的观点,if (strm == NULL)
                return false;是没有用的是吧?
      

  6.   

    new 如果分配失败的话strm == NULL;正确
      

  7.   

    new 如果分配失败的话strm == NULL;正确
    使用时会出现访问违规.
      

  8.   

    #include <new.h>
    #define BIG_NUMBER 100000000000000int handle_program_memory_depletion( size_t )
    {
       // Your code
    }
    int main( void )
    {
       _set_new_handler( handle_program_memory_depletion );
       int *pi = new int[BIG_NUMBER];
    }