|
SerializationArchive Exceptions |
unregistered_class
invalid_signature
unsupported_version
pointer_conflict
incompatible_native_format
array_size_too_short
stream_error
invalid_class_name
unregistered_class
xml_archive_parsing_error
xml_archive_tag_mismatch
boost::archive_exception
object which can be caught by an application program. These exceptions are defined
in the files
boost/archive/archive_exception.hpp.
namespace boost {
namespace archive {
class archive_exception : public std::exception
{
public:
typedef enum {
unregistered_class, // attempt to serialize a pointer of an
// an unregistered class
invalid_signature, // first line of archive does not contain
// expected string
unsupported_version, // archive created with library version subsequent
// to this one
pointer_conflict // an attempt has been made to directly serialize
// an object after having already serialized the same
// object through a pointer. Were this permitted,
// it the archive load would result in the creation
// of extraneous object.
incompatible_native_format, // attempt to read native binary format
// on incompatible platform
array_size_too_short, // array being loaded doesn't fit in array allocated
stream_error // i/o error on stream
} exception_code;
exception_code code;
archive_exception(exception_code c) : code(c) {}
virtual const char *what( ) const throw();
};
class xml_archive_exception : public virtual archive_exception
{
public:
typedef enum {
xml_archive_parsing_error, // archive doesn't contain expected data
xml_archive_tag_mismatch // start/end tag in archive doesn't match program
} exception_code;
xml_archive_exception(exception_code c){}
virtual const char *what( ) const throw( )
{
const char *msg;
switch(code){
case xml_archive_parsing_error:
msg = "unrecognized XML syntax";
break;
case xml_archive_tag_mismatch:
msg = "XML start/end tag mismatch";
break;
default:
archive_exception::what();
}
return msg;
}
};
} // archive
} // boost
unregistered_class
BOOST_ARCHIVE_CUSTOM_ARCHIVE_TYPES
macro.
invalid_signature
unsupported_version
Should it ever occur that an older program attempts to read newer archives whose format has changed, this exception is thrown.
pointer_conflict
template<class Archive>
void T::save(Archive &ar) const
{
const A * aptr = &a;
ar << aptr; // save an instance of object of class A through a pointer
...
ar << a; // save an instance of an object of class A
assert(aptr == &a); // this must be true
}
template<class Archive>
void T::load(Archive &ar)
{
A * aptr;
ar >> aptr; // create and initialize a new instance of class A
...
ar >> a; // restore state of on object of class A
assert(aptr == &a); // this won't be true
}
An object is saved first through a pointer then directly. Upon loading back
in the same sequence, we first create an new object and load in its data. Then
we load the data into another existing object. Where we started with one
object during save, we have two objects after restore. In a more realistic
situation, it could be very difficult to find this error. Fortunately,
these situations can be detected when the archive is created. When
this occurs, this exception is thrown.
incompatible_native_format
array_size_too_short
stream_error
std::stringstream ss;
std::vector<V> v;
boost::archive::text_oarchive oa(ss);
oa << v;
boost::archive::text_iarchive ia(ss);
ia >> v;
use
std::stringstream ss;
std::vector<V> v;
{
boost::archive::text_oarchive oa(ss);
oa << v;
}
{
boost::archive::text_iarchive ia(ss);
ia >> v;
}
invalid_class_name
unregistered_cast
xml_archive_parsing_error
xml_archive_tag_mismatch
© Copyright Robert Ramey 2002-2004. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)