如何获取有关boost :: xml_archive异常的更多信息

时间:2013-08-23 10:50:15

标签: c++ boost xml-serialization

您好我编写了一些代码,将一些对象序列化为xml,然后尝试从文件中反序列化它。这一直在起作用,但我突然得到了一个

terminate called after throwing an instance of 'boost::archive::archive_exception'
  what():  input stream error

所以我想我必须在某处做出改变。问题是提升不是给我任何更多的信息,有没有办法(也许是编译器标志?)来获得有关错误的更多信息?

我正在使用G ++,并提升v1.46

1 个答案:

答案 0 :(得分:0)

您可以将存档函数包含在try catch块中,并在发生异常时进行日志记录。

我做到了:

#if LIBRARY_DEBUG
    #define ARCHIVE_TRY try {
    #define ARCHIVE_CATCH } \
        catch(const std::exception& e) { \
            STACK_TRACE; \
            LOG_ERROR(std::string("Exception: "  + e.what())); \
            throw e; \
        }
#else
    #define ARCHIVE_TRY
    #define ARCHIVE_CATCH
#endif