From 8c58cb56c5acd58ee42429c8f2c6c85831681f20 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Mon, 12 Feb 2024 10:44:18 +0100 Subject: [PATCH] DPL: hide exception handling from header --- .../include/Framework/runDataProcessing.h | 43 ++----------------- Framework/Core/src/runDataProcessing.cxx | 39 +++++++++++++++++ 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/Framework/Core/include/Framework/runDataProcessing.h b/Framework/Core/include/Framework/runDataProcessing.h index bfda47d07971c..186d76499c1d6 100644 --- a/Framework/Core/include/Framework/runDataProcessing.h +++ b/Framework/Core/include/Framework/runDataProcessing.h @@ -25,7 +25,6 @@ #include "Framework/CustomWorkflowTerminationHook.h" #include "Framework/CommonServices.h" #include "Framework/WorkflowCustomizationHelpers.h" -#include "Framework/RuntimeError.h" #include "Framework/ResourcePolicyHelpers.h" #include "Framework/Logger.h" #include "Framework/CheckTypes.h" @@ -33,12 +32,6 @@ #include #include -#include - -namespace boost -{ -class exception; -} namespace o2::framework { @@ -147,9 +140,6 @@ int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& specs, std::vector const& workflowOptions, o2::framework::ConfigContext& configContext); -void doBoostException(boost::exception& e, const char*); -void doDPLException(o2::framework::RuntimeErrorRef& ref, char const*); -void doUnknownException(std::string const& s, char const*); void doDefaultWorkflowTerminationHook(); template @@ -220,41 +210,14 @@ int mainNoCatch(int argc, char** argv) resourcePolicies, callbacksPolicies, sendingPolicies, workflowOptions, configContext); } +int callMain(int argc, char** argv, int (*)(int, char**)); + int main(int argc, char** argv) { using namespace o2::framework; using namespace boost::program_options; - static bool noCatch = getenv("O2_NO_CATCHALL_EXCEPTIONS") && strcmp(getenv("O2_NO_CATCHALL_EXCEPTIONS"), "0"); - int result = 1; - if (noCatch) { - try { - result = mainNoCatch(argc, argv); - } catch (o2::framework::RuntimeErrorRef& ref) { - doDPLException(ref, argv[0]); - throw; - } - } else { - try { - // The 0 here is an int, therefore having the template matching in the - // SFINAE expression above fit better the version which invokes user code over - // the default one. - // The default policy is a catch all pub/sub setup to be consistent with the past. - result = mainNoCatch(argc, argv); - } catch (boost::exception& e) { - doBoostException(e, argv[0]); - throw; - } catch (std::exception const& error) { - doUnknownException(error.what(), argv[0]); - throw; - } catch (o2::framework::RuntimeErrorRef& ref) { - doDPLException(ref, argv[0]); - throw; - } catch (...) { - doUnknownException("", argv[0]); - throw; - } - } + int result = callMain(argc, argv, mainNoCatch); char* idstring = nullptr; for (int argi = 0; argi < argc; argi++) { diff --git a/Framework/Core/src/runDataProcessing.cxx b/Framework/Core/src/runDataProcessing.cxx index cfbb616b0d0a5..64c034ebb8533 100644 --- a/Framework/Core/src/runDataProcessing.cxx +++ b/Framework/Core/src/runDataProcessing.cxx @@ -177,6 +177,45 @@ bpo::options_description gHiddenDeviceOptions("Hidden child options"); O2_DECLARE_DYNAMIC_LOG(driver); +void doBoostException(boost::exception& e, const char*); +void doDPLException(o2::framework::RuntimeErrorRef& ref, char const*); +void doUnknownException(std::string const& s, char const*); + +int callMain(int argc, char** argv, int (*mainNoCatch)(int, char**)) +{ + static bool noCatch = getenv("O2_NO_CATCHALL_EXCEPTIONS") && strcmp(getenv("O2_NO_CATCHALL_EXCEPTIONS"), "0"); + int result = 1; + if (noCatch) { + try { + result = mainNoCatch(argc, argv); + } catch (o2::framework::RuntimeErrorRef& ref) { + doDPLException(ref, argv[0]); + throw; + } + } else { + try { + // The 0 here is an int, therefore having the template matching in the + // SFINAE expression above fit better the version which invokes user code over + // the default one. + // The default policy is a catch all pub/sub setup to be consistent with the past. + result = mainNoCatch(argc, argv); + } catch (boost::exception& e) { + doBoostException(e, argv[0]); + throw; + } catch (std::exception const& error) { + doUnknownException(error.what(), argv[0]); + throw; + } catch (o2::framework::RuntimeErrorRef& ref) { + doDPLException(ref, argv[0]); + throw; + } catch (...) { + doUnknownException("", argv[0]); + throw; + } + } + return result; +} + // Read from a given fd and print it. // return true if we can still read from it, // return false if we need to close the input pipe.