Operating System - HP-UX
1830165 Members
2759 Online
109999 Solutions
New Discussion

Need a way to globally disable std::bad_alloc

 
nayeem khan
Occasional Advisor

Need a way to globally disable std::bad_alloc

Hi

Is there any compiler flag to disable std::bad_alloc exception when new operator fails

i know that one way is to use new (nothrow),but this i will have to do it every where.

I am looking for a way to do it globally

from
nayeem khan
2 REPLIES 2
nayeem khan
Occasional Advisor

Re: Need a way to globally disable std::bad_alloc

Hi

i got one flag "-nostdnew"

i am trying with it.

from
nayeem khan
Dennis Handly
Acclaimed Contributor

Re: Need a way to globally disable std::bad_alloc

There is no flag. The default is to throw an exception. You can use set::set_new_handler to call an exception routine.

Why do you care? If you are out of heap space, there isn't much you can do, might as well abort. Are you checking for NULL?

>-nostdnew

This doesn't exist.
You could write your own replacement operator new and return NULL.