diff --git a/src/main.cpp b/src/main.cpp index 4230330..c781ab0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -109,20 +109,31 @@ int main(int argc, char *argv[]) } opts.context = vm["context"].as(); - for (const auto &match : search::search(filepath, regex, opts)) + try { - cout << match.filepath; - if (!match.headline.empty()) + for (const auto &match : + search::search(filepath, regex, opts)) { + cout << match.filepath; + if (!match.headline.empty()) + { - cout << ", " << match.headline; + cout << ", " << match.headline; + } + if (!match.page.empty()) + { + cout << ", page " << match.page; + } + cout << ": " << match.context.first << match.text + << match.context.second << '\n'; } - if (!match.page.empty()) - { - cout << ", page " << match.page; - } - cout << ": " << match.context.first << match.text - << match.context.second << '\n'; + } + catch (const std::exception &e) + { // Unknown errors. + cerr << '\n' << translate("ERROR: ") << e.what() << '\n'; + cerr << translate("Error while searching.") << '\n'; + // NOTE: Maybe we should continue with the next regex/file? + return EXIT_FAILURE; } } }