Commit 6f353f30 authored by Davis King's avatar Davis King

Improved error messages generated when reading corrupted data files.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403547
parent 0e10e1e5
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <utility> #include <utility>
#include "../algs.h" #include "../algs.h"
#include "../matrix.h" #include "../matrix.h"
#include "../string.h"
#include <vector> #include <vector>
namespace dlib namespace dlib
...@@ -56,8 +57,10 @@ namespace dlib ...@@ -56,8 +57,10 @@ namespace dlib
value_type value; value_type value;
label_type label; label_type label;
sample_type sample; sample_type sample;
long line_num = 0;
while (fin.peek() != EOF) while (fin.peek() != EOF)
{ {
++line_num;
getline(fin, line); getline(fin, line);
string::size_type pos = line.find_first_not_of(" \t\r\n"); string::size_type pos = line.find_first_not_of(" \t\r\n");
...@@ -73,7 +76,7 @@ namespace dlib ...@@ -73,7 +76,7 @@ namespace dlib
sin >> label; sin >> label;
if (!sin) if (!sin)
throw sample_data_io_error("Error while reading file " + file_name); throw sample_data_io_error("On line: " + cast_to_string(line_num) + ", error while reading file " + file_name );
// eat whitespace // eat whitespace
sin >> ws; sin >> ws;
...@@ -85,7 +88,7 @@ namespace dlib ...@@ -85,7 +88,7 @@ namespace dlib
// ignore what should be a : character // ignore what should be a : character
if (sin.get() != ':') if (sin.get() != ':')
throw sample_data_io_error("Error while reading file " + file_name); throw sample_data_io_error("On line: " + cast_to_string(line_num) + ", error while reading file " + file_name);
sin >> value >> ws; sin >> value >> ws;
...@@ -95,9 +98,6 @@ namespace dlib ...@@ -95,9 +98,6 @@ namespace dlib
} }
} }
if (sample.size() == 0)
throw sample_data_io_error("Error while reading file " + file_name + ". One sample had zero elements.");
samples.push_back(sample); samples.push_back(sample);
labels.push_back(label); labels.push_back(label);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment