From 480708b9a0aac92e00a34bf1ba988f6e0994c215 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 2 Mar 2018 19:19:37 +0000 Subject: [PATCH] Hadrons: safer error handling for HadronsXmlRun --- extras/Hadrons/Exceptions.hpp | 1 - extras/Hadrons/HadronsXmlRun.cc | 24 +++++++--- extras/Hadrons/HadronsXmlSchedule.cc | 65 ---------------------------- extras/Hadrons/Makefile.am | 5 +-- 4 files changed, 19 insertions(+), 76 deletions(-) delete mode 100644 extras/Hadrons/HadronsXmlSchedule.cc diff --git a/extras/Hadrons/Exceptions.hpp b/extras/Hadrons/Exceptions.hpp index ab588e5e..ce11618a 100644 --- a/extras/Hadrons/Exceptions.hpp +++ b/extras/Hadrons/Exceptions.hpp @@ -37,7 +37,6 @@ See the full license in the file "LICENSE" in the top level distribution directo #define SRC_LOC std::string(__FUNCTION__) + " at " + std::string(__FILE__) + ":"\ + std::to_string(__LINE__) #define HADRON_ERROR(exc, msg)\ -LOG(Error) << msg << std::endl;\ throw(Exceptions::exc(msg, SRC_LOC)); #define DECL_EXC(name, base) \ diff --git a/extras/Hadrons/HadronsXmlRun.cc b/extras/Hadrons/HadronsXmlRun.cc index 680f234b..4fcfabf2 100644 --- a/extras/Hadrons/HadronsXmlRun.cc +++ b/extras/Hadrons/HadronsXmlRun.cc @@ -56,14 +56,26 @@ int main(int argc, char *argv[]) Grid_init(&argc, &argv); // execution - Application application(parameterFileName); - - application.parseParameterFile(parameterFileName); - if (!scheduleFileName.empty()) + try { - application.loadSchedule(scheduleFileName); + Application application(parameterFileName); + + application.parseParameterFile(parameterFileName); + if (!scheduleFileName.empty()) + { + application.loadSchedule(scheduleFileName); + } + application.run(); + } + catch (const std::exception& e) + { + LOG(Error) << "FATAL ERROR -- Exception " << typeName(&typeid(e)) << std::endl; + LOG(Error) << e.what() << std::endl; + LOG(Error) << "Aborting program" << std::endl; + Grid_finalize(); + + return EXIT_FAILURE; } - application.run(); // epilogue LOG(Message) << "Grid is finalizing now" << std::endl; diff --git a/extras/Hadrons/HadronsXmlSchedule.cc b/extras/Hadrons/HadronsXmlSchedule.cc deleted file mode 100644 index 55f3b231..00000000 --- a/extras/Hadrons/HadronsXmlSchedule.cc +++ /dev/null @@ -1,65 +0,0 @@ -/************************************************************************************* - -Grid physics library, www.github.com/paboyle/Grid - -Source file: extras/Hadrons/HadronsXmlSchedule.cc - -Copyright (C) 2015-2018 - -Author: Antonin Portelli - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ - -#include - -using namespace Grid; -using namespace QCD; -using namespace Hadrons; - -int main(int argc, char *argv[]) -{ - // parse command line - std::string parameterFileName, scheduleFileName; - - if (argc < 3) - { - std::cerr << "usage: " << argv[0] << " [Grid options]"; - std::cerr << std::endl; - std::exit(EXIT_FAILURE); - } - parameterFileName = argv[1]; - scheduleFileName = argv[2]; - - // initialization - Grid_init(&argc, &argv); - - // execution - Application application; - - application.parseParameterFile(parameterFileName); - application.schedule(); - application.printSchedule(); - application.saveSchedule(scheduleFileName); - - // epilogue - LOG(Message) << "Grid is finalizing now" << std::endl; - Grid_finalize(); - - return EXIT_SUCCESS; -} diff --git a/extras/Hadrons/Makefile.am b/extras/Hadrons/Makefile.am index 477b93e4..3b393cd1 100644 --- a/extras/Hadrons/Makefile.am +++ b/extras/Hadrons/Makefile.am @@ -1,5 +1,5 @@ lib_LIBRARIES = libHadrons.a -bin_PROGRAMS = HadronsXmlRun HadronsXmlSchedule +bin_PROGRAMS = HadronsXmlRun include modules.inc @@ -29,6 +29,3 @@ nobase_libHadrons_a_HEADERS = \ HadronsXmlRun_SOURCES = HadronsXmlRun.cc HadronsXmlRun_LDADD = libHadrons.a -lGrid - -HadronsXmlSchedule_SOURCES = HadronsXmlSchedule.cc -HadronsXmlSchedule_LDADD = libHadrons.a -lGrid