Topic: Q: new / new_handler / set_new_handler / C+


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/05/01
Raw View
In article bmh@troll.vestnett.no, Dag Haugen <idb@vestnett.no> writes:
>In all C++ programs I have written so far, I have assumed
>that the  "void* operator new(size_t)"  returns either a
>pointer to memory of the size I requested *or* it returns
>0. In the new draft standard, the default new handler
>throws an exception. This means that the default behavior
>of new has changed dramatically, and all tests for 0
>after my new-calls are just waste of time. To "fix" this,
>the draft allows me to call "set_new_handler(0)", which
>*can* make the operator new return 0 instead of throwing
>an exception. This is not defined in the draft ("the result
>is implementation-defined"), but is suggested as a solution
>"in accordance with many earlier implementations of C++".

If you look at the version of the draft released for public comment,
you will find the situation has changed. The draft is available for
FTP from
        research.att.com, directory dist/c++std/WP

There are now two versions of operator new -- one which always
throws an exception on failure, and one which always returns
zero on failure.
---
Steve Clamage, stephen.clamage@eng.sun.com