Why a try/catch in priority_queue::push/pop?!?
Paolo Carlini
pcarlini@suse.de
Thu Aug 3 18:42:00 GMT 2006
Hi,
today I noticed by chance these strange things: for example, push
(likewise pop):
void
push(const value_type& __x)
{
try
{
c.push_back(__x);
std::push_heap(c.begin(), c.end(), comp);
}
catch(...)
{
c.clear();
__throw_exception_again;
}
}
why that try/catch? Certainly I cannot find support in the Standard for
its presence and, AFAICS, can also run against reasonable user
expectations: i.e., if c.push_back throws (e.g., bad_alloc) the user may
reasonably expect that c remains unchanged! The case of push_heap is
different, more complex, but again, I don't think the user, basing on
the letter of the Standard can generally (i.e., portably) expect that a
clear() will be invoked (supposedly to do him the "favor" of a
"consistent", read, empty! , container)
I think the try/catch is very old, coming from the HP/SGI STL, maybe I
missing historical facts which I'd like to know... Anyone helping?
Thanks,
Paolo.
More information about the Libstdc++
mailing list