g++: new that throw bad_alloc ?

Kriang Lerdsuwanakij lerdsuwa@scf-fs.usc.edu
Thu Oct 9 16:52:00 GMT 1997


Hi,

We have a working exception handling that is on by default, definition
of bad_alloc and new (nothrow).  It would be nice to have the ability to
let new throw bad_alloc rather than displaying the virtual memory
exhausted message.   That error should be able to be trapped by the
program.   

Here is my idea how it might be implemented:

Make the default new handler check a flag when called.  The default
behavior is to display a message and exit for backward compatibility.  
The flag can be modified by a global constructor, which is added to the
object file when some option, say, -fbad_alloc is supplied to gcc/g++.
libgcc2.a is built without the -fbad_alloc option.

I guess there is no problem with duplicate global constructors when many
files are compiled with the option.  The linker should be able to remove
them just like duplicate template instantiations.

Kriang
lerdsuwa@scf.usc.edu



More information about the Gcc mailing list