From d72dcd89ea3ab28a27db76af2f4210f50f01559b Mon Sep 17 00:00:00 2001 From: Yuliya Zhornyak Date: Fri, 5 Apr 2024 10:50:27 +0300 Subject: [PATCH] issue:2481 - Unhandled Exception on non-existent file --- src/bin/lpython.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index ea8c873c88..70a10a1215 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -1789,12 +1789,18 @@ int main(int argc, char *argv[]) // TODO: for now we ignore the other filenames, only handle // the first: - std::string arg_file = arg_files[0]; - if (CLI::NonexistentPath(arg_file).empty()){ - std::cerr << "The input file does not exist: " << arg_file << std::endl; - return 1; + try { + std::string arg_file = arg_files[0]; + if (CLI::NonexistentPath(arg_file).empty()) { + std::cerr << "Error: The input file does not exist: " << arg_file << std::endl; + return 1; + } + return 0; + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + return 1; } - std::string outfile; std::string basename; basename = remove_extension(arg_file);