Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2001-09-10 13:59:56

At 10:17 AM 9/10/2001, Ed Brey wrote:

>From: "Beman Dawes" <bdawes_at_[hidden]>
>> * There are many functions where a reasonable implementation may wish
>> allocate memory. These should be documented as potentially throwing
>> std::bad_alloc. Like the standard library, it seems to me this can
>> done with a blanket "any function may throw std::bad_alloc" statement
>> rather than try to guess which functions an implementation may wish to
>> dynamic memory allocation.
>No-throw guarantees for low-level libraries can make writing code that
>the library a lot easier. I'd hate to give this up just to avoid having
>predict which functions will and won't allocate, since doing so doesn't
>seem too hard. IMHO, the blanket statement should probably be nothrow,
>with bad_alloc listed among the exceptions for the appropriate functions.

You are going to have a time convincing the standards committee of that,
I'd guess. It is a rare function that someone in the LWG can't come up
with a valid reason for wanting to do memory allocation in. Even if they
can't, the implementors don't want their hands tied. Notice how few places
there are in the standard where bad_alloc is prohibited.

While Boost in general and Boost.Threads in particular doesn't have to
follow the same approach as the standard, it will be easier in the long run
if we do so.

That said, maybe we can be a bit more helpful to users by identifying
certain functions as meeting more stringent exception safety guarantees.


Boost list run by bdawes at, gregod at, cpdaniel at, john at