Skip to content

Commit

Permalink
DPL: hide exception handling from header
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf committed Feb 12, 2024
1 parent 314755c commit 8c58cb5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
43 changes: 3 additions & 40 deletions Framework/Core/include/Framework/runDataProcessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,13 @@
#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"
#include "Framework/StructToTuple.h"

#include <vector>
#include <cstring>
#include <exception>

namespace boost
{
class exception;
}

namespace o2::framework
{
Expand Down Expand Up @@ -147,9 +140,6 @@ int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& specs,
std::vector<o2::framework::ConfigParamSpec> 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 <typename T>
Expand Down Expand Up @@ -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++) {
Expand Down
39 changes: 39 additions & 0 deletions Framework/Core/src/runDataProcessing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8c58cb5

Please sign in to comment.