try {
if (argc != 2) {
throw std::runtime_error("Usage: ./client <filename>");
}
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query("127.0.0.1", "8080");
boost::asio::ip::tcp::socket socket(io_service);
boost::asio::connect(socket, resolver.resolve(query));
std::string filename(argv[1]);
std::ifstream file(filename);
if (!file.is_open()) {
throw std::runtime_error("Failed to open file");
}
std::string line;
while (std::getline(file, line)) {
boost::asio::write(socket, boost::asio::buffer(line + "\n"));
}
boost::asio::streambuf response_buf;
boost::asio::read_until(socket, response_buf, "\n");
std::istream input(&response_buf);
int num_records;
input >> num_records;
std::ofstream protocol_file("protocol.txt", std::ios_base::app);
if (!protocol_file.is_open()) {
throw std::runtime_error("Failed to open protocol file");
}
protocol_file << "Filename: " << filename << ", Records processed: " << num_records << std::endl;
} catch (exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
return 0;
}
Компилятор ругается на exception (в конце кода, чтобы не искать). Не пойму в чем проблема. Кто может подсказать?
std::exception
Обсуждают сегодня