|
1 | | -#include <cassert> |
2 | 1 | #include <cstdlib> |
3 | 2 | #include <fstream> |
4 | 3 | #include <iostream> |
5 | 4 | #include <sstream> |
| 5 | +#include <stdexcept> |
6 | 6 | #include <string> |
7 | 7 | #include <unordered_map> |
8 | 8 | #include <utility> |
@@ -32,19 +32,24 @@ Dataset<int, std::string> load_movielens(const std::string& path) { |
32 | 32 | // read movies |
33 | 33 | std::unordered_map<std::string, std::string> movies; |
34 | 34 | std::ifstream movies_file(path + "/u.item"); |
35 | | - assert(movies_file.is_open()); |
| 35 | + if (!movies_file.is_open()) { |
| 36 | + throw std::runtime_error{"Could not open file"}; |
| 37 | + } |
36 | 38 | while (std::getline(movies_file, line)) { |
37 | 39 | std::string::size_type n = line.find('|'); |
38 | 40 | std::string::size_type n2 = line.find('|', n + 1); |
39 | 41 | movies.emplace( |
40 | | - std::make_pair(line.substr(0, n), convert_to_utf8(line.substr(n + 1, n2 - n - 1))) |
| 42 | + line.substr(0, n), |
| 43 | + convert_to_utf8(line.substr(n + 1, n2 - n - 1)) |
41 | 44 | ); |
42 | 45 | } |
43 | 46 |
|
44 | 47 | // read ratings and create dataset |
45 | 48 | Dataset<int, std::string> data; |
46 | 49 | std::ifstream ratings_file(path + "/u.data"); |
47 | | - assert(ratings_file.is_open()); |
| 50 | + if (!ratings_file.is_open()) { |
| 51 | + throw std::runtime_error{"Could not open file"}; |
| 52 | + } |
48 | 53 | while (std::getline(ratings_file, line)) { |
49 | 54 | std::string::size_type n = line.find('\t'); |
50 | 55 | std::string::size_type n2 = line.find('\t', n + 1); |
|
0 commit comments