Instead of worrying:-
1. How does the programmer know about how the exception going to catch?
2. The programmer has to be aware that he/she is dealing with CRT’s version of new or standard version of new.
Let’s put in alternative point of view:
What if the programmer knows that the new operator is NOT going to throwing any exceptions?
Thus, std::nothrow new would be the best solution. This will guarantee that the new will only return either a NULL pointer or a valid pointer.
Here is the sample usage:
Foo *p; p = new(std::nothrow) Foo(); if( !p ) { exit(1); }
reference
1. msdn reference
2. C++ reference guide
No comments:
Post a Comment