|
Boost : |
Subject: Re: [boost] [Thread] Win32 exception handling
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-11-26 02:27:44
----- Original Message -----
From: "Alexander Terekhov" <terekhov_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, November 26, 2008 12:42 AM
Subject: Re: [boost] [Thread] Win32 exception handling
>
>
> "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?
Why the operation can throw std::bad_alloc? You have used std::nothrow, so
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk