From edbfdb5ef3372df47ec61c75af8ff2dd2e8c83ee Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Thu, 3 Nov 2016 16:02:04 +0100 Subject: [PATCH] FlowMain: make sure to always print exception messages to the terminal this patch only uses OpmLog if it is set up properly, else it uses std::cout. the reason why this is needed is that there's a chicken-and-egg problem: exceptions which are thrown before the logging system has been initialized -- most prominently while parsing the deck -- cause the simulator to silently abort without any user notification which can be very confusing. On the other hand, initializing the logging system requires a fully initialized EclipseState object, i.e. currently to initialze the logging system the deck must be parsed and in order to print the exceptions thrown while parsing the deck one needs the logging system. v2: only prevent using the logging system if has not been set up. thanks to [at]blattms for the suggestion! --- opm/autodiff/FlowMain.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 1ee7fa7a4..95092e7e2 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -166,7 +166,14 @@ namespace Opm if( output_cout_ ) { - OpmLog::error(message.str()); + // in some cases exceptions are thrown before the logging system is set + // up. + if (OpmLog::hasBackend("STREAMLOG")) { + OpmLog::error(message.str()); + } + else { + std::cout << message.str() << "\n"; + } } return EXIT_FAILURE;