c++ - what does it mean for `new` to be no-throw guaranteed when bad_alloc is not thrown -


from documentation of new:

the first version (1) throws bad_alloc if fails allocate storage. otherwise, throws no exceptions (no-throw guarantee).

to me, should mean code

#include <new>  struct a{     a(){         throw 0;     }   };  int main(){     try{         a* = new a;     }     catch(std::bad_alloc&){} } 

is fine. however, when compiling gcc (see here), program terminates after throwing int.

that's documentation of operator new, not same new expression. new expression calls operator new obtain memory and then calls constructor requested on memory. operator new not throw other std::bad_alloc, later call constructor can throw whatever user code wants.

compare new expression operator new.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -