www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - operator new() still returns NULL?!

↑ ↓ ← "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
Is this correct? I've just been surprised to see that the following 
code produces "NULL returned", and not "bad_alloc"

    {
        try
        {
            char    *pch    =   new char[2000000000];

            if(NULL == pch)
            {
                fprintf(stderr, "NULL returned\n");
            }
        }
        catch(std::bad_alloc &)
        {
            fprintf(stderr, "bad_alloc\n");
        }
        catch(std::exception &x)
        {
            fprintf(stderr, "exception: %s\n", x.what());
        }
        catch(...)
        {
            fprintf(stderr, "exception of unknown type\n");
        }
    }


What gives?!

Matthew
Jul 03 2005
↑ ↓ "Walter" <newshound digitalmars.com> writes:
"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message
news:daad5l$2t23$1 digitaldaemon.com...
 Is this correct? I've just been surprised to see that the following
 code produces "NULL returned", and not "bad_alloc"

It still returns NULL, that's correct. It's that way to support older code, such as MFC. I know it'll eventually have to be fixed.
Jul 04 2005
↑ ↓ → "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
I've found a workaround, in that I've emulated the somewhat scary 
tactic of DMC++'s STLport that throws bad_alloc from std::allocator 
even though operator new() does not.

Still, it will have to be fixed. ;)

"Walter" <newshound digitalmars.com> wrote in message 
news:daaqqi$dpa$2 digitaldaemon.com...
 "Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message
 news:daad5l$2t23$1 digitaldaemon.com...
 Is this correct? I've just been surprised to see that the 
 following
 code produces "NULL returned", and not "bad_alloc"

It still returns NULL, that's correct. It's that way to support older code, such as MFC. I know it'll eventually have to be fixed.

Jul 04 2005