Started with boost/serialization error handling.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 10 Aug 2009 08:36:47 +0000 (10:36 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Mon, 10 Aug 2009 08:38:08 +0000 (10:38 +0200)
src/config.cpp
src/logger.cpp
src/logger.h

index 9b6f61b..62a0369 100644 (file)
@@ -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();
     }
index ae5b97a..0523442 100644 (file)
@@ -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;
+}
index d3642f2..471fa4e 100644 (file)
@@ -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