
25 Nov
2008
25 Nov
'08
11:42 p.m.
"vicente.botet" wrote: [...]
Why do you associate an exception to a broken program state?
Example: Suppose that your operation's documentation says that it may need heap unless the caller provides X() amount of memory via void * parameter to be used instead of heap (void * p is not zero). #include <new> void operation(void * p) throw (std::bad_alloc); // may throw if p == 0 size_t X(); #include <new> int main() { if (void * const p = new(std::nothrow) char [X()]) { // ... nothrow operation(p); } else { // ... nothrow } // ... nothrow } What if your operation still throws std::bad_alloc? regards, alexander.