{
     //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());
 
     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();
     }
 
 }
 
 
+/**
+ * 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 )
         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;
+}
 
     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