From 0079e977109bfa1a4226bc399fb7888d28292b3c Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 27 Jan 2010 03:17:47 +0100 Subject: added try ... catch for each line and warn if error at line --- src/base/songloading/songloading_strategy_txt.cpp | 60 +++++++++++++---------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/base/songloading/songloading_strategy_txt.cpp b/src/base/songloading/songloading_strategy_txt.cpp index 26809d2a..0f9e3fff 100644 --- a/src/base/songloading/songloading_strategy_txt.cpp +++ b/src/base/songloading/songloading_strategy_txt.cpp @@ -138,38 +138,44 @@ namespace usdx bool SongloadingStrategyTxt::parse_line(Song* song, File& file, const int line_number) { - std::string line; - std::getline(file.stream(), line); + try { + std::string line; + std::getline(file.stream(), line); - char type; - std::istringstream linestream(line); - linestream >> std::skipws >> type; + char type; + std::istringstream linestream(line); + linestream >> std::skipws >> type; - if (type == '#') { - // ignore, header already read - } - else if (type == 'E') { - // song end - if (file.stream().eof()) { - LOG4CXX_WARN(log, "End marker found in line " << line_number << - " before end of file: '" << song->get_filename() << "'."); + if (type == '#') { + // ignore, header already read } + else if (type == 'E') { + // song end + if (file.stream().eof()) { + LOG4CXX_WARN(log, "End marker found in line " << line_number << + " before end of file: '" << song->get_filename() << "'."); + } - return false; - } - else if (type == '-') { - parse_newline(song, linestream, line_number); - } - else if (type == 'B') { - parse_bpm(song, linestream, line_number); - } - else if (type == ':' || type == 'F' || type == '*') { - parse_note(song, type, linestream, line_number); + return false; + } + else if (type == '-') { + parse_newline(song, linestream, line_number); + } + else if (type == 'B') { + parse_bpm(song, linestream, line_number); + } + else if (type == ':' || type == 'F' || type == '*') { + parse_note(song, type, linestream, line_number); + } + else { + LOG4CXX_WARN(log, "Unknown line in song: '" << line << + "' in file: " << song->get_filename() << + " at line " << line_number); + } } - else { - LOG4CXX_WARN(log, "Unknown line in song: '" << line << - "' in file: " << song->get_filename() << - " at line " << line_number); + catch (std::exception &e) { + LOG4CXX_WARN(log, "Error in song file at line " << + line_number << ": " << e.what()); } return true; -- cgit v1.2.3