Raise error if file doesn't exist.

This commit is contained in:
Mathieu Blondel 2011-06-21 17:57:21 +09:00
parent 5bdc3ab5e6
commit e304597fab
2 changed files with 7 additions and 0 deletions

View File

@ -269,6 +269,9 @@ void parse_file(char const *file_path,
file_stream.rdbuf()->pubsetbuf(&buffer[0], buffer_size);
file_stream.open(file_path);
if (!file_stream)
throw std::ios_base::failure("File doesn't exist!");
std::string line;
while (std::getline(file_stream, line))
parse_line(line, data, indices, indptr, labels);

View File

@ -67,3 +67,7 @@ def test_load_invalid_file():
@raises(TypeError)
def test_not_a_filename():
load_svmlight_file(1)
@raises(IOError)
def test_invalid_filename():
load_svmlight_file("trou pic nic douille")