From a1d63d3fa0c6794e1f9abe4057bfe314b0ba12e6 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Thu, 16 Aug 2018 13:08:43 +0200 Subject: [PATCH] Catch the exception from the Qt impl. of XmlGmlInterface. --- Applications/DataExplorer/mainwindow.cpp | 14 ++++++++++++-- Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp | 15 ++++++++++++--- Applications/Utils/GeoTools/MoveGeometry.cpp | 11 ++++++++++- .../Utils/GeoTools/TriangulatePolyline.cpp | 13 +++++++++++-- .../Utils/OGSFileConverter/OGSFileConverter.cpp | 14 ++++++++++++-- 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp index 62c78169fe1..b0a850888ba 100644 --- a/Applications/DataExplorer/mainwindow.cpp +++ b/Applications/DataExplorer/mainwindow.cpp @@ -497,8 +497,18 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) else if (fi.suffix().toLower() == "gml") { GeoLib::IO::XmlGmlInterface xml(_project.getGEOObjects()); - if (!xml.readFile(fileName)) - OGSError::box("Failed to load geometry.\n Please see console for details."); + try + { + if (!xml.readFile(fileName)) + OGSError::box( + "Failed to load geometry.\n Please see console for " + "details."); + } + catch (std::runtime_error const& err) + { + OGSError::box(err.what(), + "Failed to read file `" + fileName + "'"); + } } // OpenGeoSys observation station files (incl. boreholes) else if (fi.suffix().toLower() == "stn") diff --git a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp index f37e62bd8c3..9a2b1a7118a 100644 --- a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp +++ b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp @@ -18,13 +18,14 @@ #include <QtXml/QDomDocument> #include <logog/include/logog.hpp> +#include "Applications/DataExplorer/Base/OGSError.h" +#include "Applications/DataHolderLib/FemCondition.h" + #include "BaseLib/BuildInfo.h" #include "BaseLib/FileFinder.h" #include "BaseLib/FileTools.h" #include "BaseLib/IO/Writer.h" -#include "Applications/DataHolderLib/FemCondition.h" - #include "GeoLib/GEOObjects.h" #include "GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h" @@ -75,7 +76,15 @@ int XmlPrjInterface::readFile(const QString& fileName) if (node_name == "geometry") { GeoLib::IO::XmlGmlInterface gml(_project.getGEOObjects()); - gml.readFile(QString(path + file_name)); + try + { + gml.readFile(QString(path + file_name)); + } + catch (std::runtime_error const& err) + { + OGSError::box(err.what(), + "Failed to read file `" + fileName + "'"); + } } else if (node_name == "stations") { diff --git a/Applications/Utils/GeoTools/MoveGeometry.cpp b/Applications/Utils/GeoTools/MoveGeometry.cpp index ee5f58e3a68..573ee813774 100644 --- a/Applications/Utils/GeoTools/MoveGeometry.cpp +++ b/Applications/Utils/GeoTools/MoveGeometry.cpp @@ -50,8 +50,17 @@ int main(int argc, char *argv[]) GeoLib::GEOObjects geo_objects; GeoLib::IO::XmlGmlInterface xml(geo_objects); - if (!xml.readFile(geo_input_arg.getValue())) + try { + if (!xml.readFile(geo_input_arg.getValue())) + { + return EXIT_FAILURE; + } + } + catch (std::runtime_error const& err) + { + ERR("Failed to read file `%s'.", geo_input_arg.getValue().c_str()); + ERR("%s", err.what()); return EXIT_FAILURE; } diff --git a/Applications/Utils/GeoTools/TriangulatePolyline.cpp b/Applications/Utils/GeoTools/TriangulatePolyline.cpp index f643e4fe01e..46484850ee6 100644 --- a/Applications/Utils/GeoTools/TriangulatePolyline.cpp +++ b/Applications/Utils/GeoTools/TriangulatePolyline.cpp @@ -56,9 +56,18 @@ int main(int argc, char *argv[]) GeoLib::GEOObjects geo_objects; GeoLib::IO::XmlGmlInterface xml(geo_objects); - if (!xml.readFile(file_name)) + try { - ERR ("Failed to load geometry file."); + if (!xml.readFile(file_name)) + { + ERR("Failed to load geometry file."); + return EXIT_FAILURE; + } + } + catch (std::runtime_error const& err) + { + ERR("Failed to read file `%s'.", file_name.c_str()); + ERR("%s", err.what()); return EXIT_FAILURE; } diff --git a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp index 9088768c7a4..dbcda6beab5 100644 --- a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp +++ b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp @@ -53,11 +53,21 @@ void OGSFileConverter::convertGML2GLI(const QStringList &input, const QString &o if (fileExists(output_str)) continue; - if (!xml.readFile(input_string)) + try { - OGSError::box("Error reading geometry " + fi.fileName()); + if (!xml.readFile(input_string)) + { + OGSError::box("Error reading geometry " + fi.fileName()); + continue; + } + } + catch (std::runtime_error const& err) + { + OGSError::box(err.what(), + "Failed to read file `" + input_string + "'"); continue; } + std::vector<std::string> geo_names; geo_objects.getGeometryNames(geo_names); FileIO::Legacy::writeGLIFileV4(output_str, geo_names[0], geo_objects); -- GitLab