Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Inventive hack to get flex raising exceptions on parse error
[simgrid.git] / src / surf / xml / surfxml_sax_cb.cpp
index ffec861..0b49682 100644 (file)
@@ -40,6 +40,10 @@ void surf_parse_assert(bool cond, std::string&& msg)
     surf_parse_error(std::move(msg));
 }
 
+void surf_parse_error(const char* msg) {
+  throw simgrid::ParseError(surf_parse_lineno, surf_parsed_filename, std::string(msg));
+}
+
 void surf_parse_error(std::string&& msg)
 {
   throw simgrid::ParseError(surf_parse_lineno, surf_parsed_filename, std::move(msg));
@@ -1001,10 +1005,9 @@ void surf_parse_open(const std::string& file)
   surf_path.push_back(dir);
 
   surf_file_to_parse = surf_fopen(file, "r");
-  if (surf_file_to_parse == nullptr) {
-    std::string cwd = simgrid::xbt::Path().get_name();
-    xbt_die("Unable to open '%s' from '%s'\n", file.c_str(), cwd.c_str());
-  }
+  if (surf_file_to_parse == nullptr)
+    throw std::invalid_argument(std::string("Unable to open ')") + file + "' from '" + simgrid::xbt::Path().get_name() +
+                                "'. Does this file exist?");
   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
   surf_parse__switch_to_buffer(surf_input_buffer);
   surf_parse_lineno = 1;