|
Boost Users : |
From: gast128 (gast128_at_[hidden])
Date: 2007-03-01 14:18:49
Dear all,
I ran into an exception thrown by the constructor. But there is no way to
call 'delete_created_pointers' on the object since the object is never fully
created (see below)
Is there something to do about?
void Foo()
{
std::vector<Bus> v(2); //from the examples
std::stringstream sstr;
//save
try
{
_ASSERT(sstr.good());
boost::archive::xml_oarchive oa(sstr);
oa << BOOST_SERIALIZATION_NVP(v);
}
catch (boost::archive::archive_exception& re)
{
DBG_TRACEN(re.what());
}
//load
v.clear();
//sstr.seekg(0);
sstr.seekg(1); //generate dileberate error
boost::archive::xml_iarchive* p = NULL;
try
{
_ASSERT(sstr.good());
boost::archive::xml_iarchive ia(sstr);
p = &ia;
ia >> BOOST_SERIALIZATION_NVP(v);
}
catch (boost::archive::archive_exception& re)
{
DBG_TRACEN(re.what());
//won't work: p is always NULL
if (p)
{
p->delete_created_pointers();
}
}
}
This throwing c++ constructor stuff is btw the way to transport errors
according to a lot of c++ gurus. But my persnonal opinion is that it sucks.
Every created object must be guarded with exception safety. For large
applications, this exception mecahnism is very tricky and sources for a lot
unwanted application terminations or memory leaks.
Wkr
me
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net