|
Boost : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2004-01-02 13:04:46
Could we not consider augmenting throw_exception.hpp to
something like the following? Is there any reason why this
wouldn't be a good idea?
#include <boost/config.hpp>
#ifdef BOOST_NO_EXCEPTIONS
# include <exception>
#endif
namespace boost {
#ifdef BOOST_NO_EXCEPTIONS
// user defined
void throw_exception(std::exception const & e);
void throw_exception();
} // namespace boost
#define BOOST_TRY
#define BOOST_CATCH(x) if(0)
#else
template<class E> void throw_exception(E const & e)
{
throw e;
}
inline void throw_exception()
{
throw;
}
#define BOOST_TRY try
#define BOOST_CATCH(x) catch(x)
#endif
} // namespace boost
This would permit me me to do the following:
template<class Archive>
void D::load(Archive & ar, const unsigned int file_version)
{
BOOST_TRY {
ar >> boost::serialization::make_nvp("b", b1);
ar >> boost::serialization::make_nvp("b", b2);
}
BOOST_CATCH (...){
// eliminate invalid pointers
b1 = NULL;
b2 = NULL;
boost::throw_exception();
}
// check that loading was correct
BOOST_CHECK(b1 == b2);
}
Robert Ramey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk