From 5d38cfe6c4a5ef860503af130563e18081d70a0b Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Mon, 10 Aug 2009 10:36:47 +0200 Subject: [PATCH] Started with boost/serialization error handling. --- src/config.cpp | 15 ++++++++++++--- src/logger.cpp | 20 ++++++++++++++++++++ src/logger.h | 2 ++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 9b6f61b..62a0369 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -94,7 +94,7 @@ int Config::serialize_services() { //TODO: error handling - // First of all we have to put all service objects in a Serviceholder object. + // First of all we have to put all Service objects in a Serviceholder object. ServiceholderPtr service_holder(new Serviceholder()); @@ -117,8 +117,17 @@ int Config::serialize_services() if ( ofs.is_open() ) { Serviceholder* _service_holder = service_holder.get(); - boost::archive::text_oarchive oa(ofs); - oa << _service_holder; + try + { + boost::archive::text_oarchive oa(ofs); + oa << _service_holder; + } + catch( boost::archive_exception e ) + { + Log->print_exception_serialize(e.what()); + ofs.close(); + return -1; + } ofs.close(); } diff --git a/src/logger.cpp b/src/logger.cpp index ae5b97a..0523442 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -568,6 +568,16 @@ void Logger::print_deserialized_objects_success() } +/** + * Prints out the content of a service object. + * @param message Message to be added on output first. + * @param protocol Service's protocol. + * @param hostname Service's hostname. + * @param login Service's login. + * @param password Service's password. + * @param actual_ip Service's actual_ip. + * @param lastupdated Service's lastupdated. + */ void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const string& actual_ip, const int lastupdated) { if ( 1 <= Loglevel ) @@ -583,3 +593,13 @@ void Logger::print_service_object(const string& message, const string& protocol, log_notice(msg.str()); } } + + +/** + * Caught exception while serialize. + * @param exception Exception message. + */ +void print_exception_serialize(const string& exception) +{ + cout << "Error while trying to serialize Serviceholder object: " << exception << endl; +} diff --git a/src/logger.h b/src/logger.h index d3642f2..471fa4e 100644 --- a/src/logger.h +++ b/src/logger.h @@ -105,6 +105,8 @@ public: void print_deserialized_objects_success(); void print_service_object(const std::string&, const std::string&, const std::string&, const std::string&, const std::string&, const std::string&, const int); + + void print_exception_serialize(const std::string&); }; #endif -- 1.7.1