From a2696b27a9aa821aad70e4530bb22eb3a9b011d6 Mon Sep 17 00:00:00 2001
From: Martin Beseda <martin.beseda@vsb.cz>
Date: Mon, 21 Jan 2019 17:46:14 +0100
Subject: [PATCH] ENH: Added check of filepath existence.

---
 src/Network/NeuralNetwork.cpp | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/Network/NeuralNetwork.cpp b/src/Network/NeuralNetwork.cpp
index abd04579..ed0f9ad5 100644
--- a/src/Network/NeuralNetwork.cpp
+++ b/src/Network/NeuralNetwork.cpp
@@ -39,9 +39,19 @@ namespace lib4neuro {
 
     NeuralNetwork::NeuralNetwork(std::string filepath) {
         ::std::ifstream ifs(filepath);
-        boost::archive::text_iarchive ia(ifs);
-        ia >> *this;
-        ifs.close();
+        if(ifs.is_open()) {
+            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 '" + filepath + "' couldn't be open!");
+        }
+
     }
 
     NeuralNetwork::~NeuralNetwork() {
-- 
GitLab