From 763e5b24da5094577ff4a0c1ad66f899ea5a171d Mon Sep 17 00:00:00 2001
From: Martin Beseda <martin.beseda@vsb.cz>
Date: Tue, 15 Jan 2019 16:09:49 +0100
Subject: [PATCH] ENH: Added check when DataSet constructor gets path to the
 file, which is not a correct DataSet archive.

---
 src/DataSet/DataSet.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/DataSet/DataSet.cpp b/src/DataSet/DataSet.cpp
index 2a1eee46..4a176ea7 100644
--- a/src/DataSet/DataSet.cpp
+++ b/src/DataSet/DataSet.cpp
@@ -22,8 +22,13 @@ namespace lib4neuro {
     DataSet::DataSet(std::string file_path) {
         std::ifstream ifs(file_path);
         if(ifs.is_open()) {
-            boost::archive::text_iarchive ia(ifs);
-            ia >> *this;
+            try {
+                boost::archive::text_iarchive ia(ifs);
+                ia >> *this;
+            }catch(boost::archive::archive_exception& e) {
+                THROW_RUNTIME_ERROR("Serialized archive error: '" + e.what() + "'! Please, check if your file is really "
+                                                                               "the serialized DataSet.");
+            }
             ifs.close();
         } else {
             THROW_RUNTIME_ERROR("File " + file_path + " couldn't be open!");
-- 
GitLab