Topic: set_new_handler()
Author: Stephen.Clamage@Eng.Sun.COM (Steve Clamage)
Date: 1997/04/12 Raw View
In article 356162674@newshost, ross.canning@compucat.com.au (Ross Canning) writes:
>I understand that the C++ standard now includes the 'nothrow' modifier
>to specify that a 'new' is to return 0 if it fails rather than throw
>an exception.
>
>What is the status of set_new_handler()? Is it now obsolete?
The same as it has always been. If any version of operator new is unable
to find storage, it looks for an installed new_handler.
If there is a new_handler, operator new calls the handler and tries again
to get the requested memory. (This implies some things about what a
new_handler ought to do.)
If no new_handler is installed, operator new fails, either by throwing
a bad_alloc exception, or by returning a null pointer, depending on
whether is a normal or a no-throw version.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/04/13 Raw View
ross.canning@compucat.com.au (Ross Canning) writes:
>I understand that the C++ standard now includes the 'nothrow' modifier
>to specify that a 'new' is to return 0 if it fails rather than throw
>an exception.
>
>What is the status of set_new_handler()? Is it now obsolete?
The set_new_handler() function still works. It is not obsolete. It is
useful if you want resumption semantics rather than termination
semantics (exceptions basically give you termination semantics). For
example, a new handler could display an "Out of memory -- retry, abort,
fail?" message; then if the user selects retry, it could return, and if
the user selects abort, it could call exit(), and if the user selects
fail, it could throw a bad_alloc exception. The new handler is called
for both the normal and the `nothrow' forms of `new' if they run out of
memory. If the new handler throws, then the `nothrow' form of new will
return catch the exception and return 0.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: ross.canning@compucat.com.au (Ross Canning)
Date: 1997/04/10 Raw View
I understand that the C++ standard now includes the 'nothrow' modifier
to specify that a 'new' is to return 0 if it fails rather than throw
an exception.
What is the status of set_new_handler()? Is it now obsolete?
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]