21 #ifndef OPM_DEFERREDLOGGINGERRORHELPERS_HPP
22 #define OPM_DEFERREDLOGGINGERRORHELPERS_HPP
24 #include <opm/simulators/utils/DeferredLogger.hpp>
25 #include <opm/simulators/utils/gatherDeferredLogger.hpp>
27 #include <opm/material/common/Exceptions.hpp>
29 #include <opm/simulators/utils/ParallelCommunication.hpp>
46 #define OPM_DEFLOG_THROW(Exception, message, deferred_logger) \
48 std::ostringstream oss__; \
49 oss__ << "[" << __FILE__ << ":" << __LINE__ << "] " << message; \
50 deferred_logger.error(oss__.str()); \
51 throw Exception(oss__.str()); \
56 void _throw(Opm::ExceptionType::ExcEnum exc_type,
57 const std::string& message,
58 Opm::Parallel::Communication comm)
60 auto global_exc = comm.max(exc_type);
63 case Opm::ExceptionType::NONE:
65 case Opm::ExceptionType::RUNTIME_ERROR:
66 throw std::runtime_error(message);
68 case Opm::ExceptionType::INVALID_ARGUMENT:
69 throw std::invalid_argument(message);
71 case Opm::ExceptionType::NUMERICAL_ISSUE:
72 throw Opm::NumericalIssue(message);
74 case Opm::ExceptionType::DEFAULT:
75 case Opm::ExceptionType::LOGIC_ERROR:
76 throw std::logic_error(message);
79 throw std::logic_error(message);
87 inline void checkForExceptionsAndThrow(Opm::ExceptionType::ExcEnum exc_type,
88 const std::string& message,
89 Opm::Parallel::Communication comm)
91 _throw(exc_type, message, comm);
95 Opm::ExceptionType::ExcEnum exc_type,
96 const std::string& message,
97 const bool terminal_output,
98 Opm::Parallel::Communication comm)
102 if (terminal_output) {
109 _throw(exc_type, message, comm);
117 #define OPM_BEGIN_PARALLEL_TRY_CATCH() \
118 std::string obptc_exc_msg; \
119 auto obptc_exc_type = Opm::ExceptionType::NONE; \
125 #define OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, \
127 catch (const Opm::NumericalIssue& e){ \
128 obptc_exc_type = Opm::ExceptionType::NUMERICAL_ISSUE; \
129 obptc_exc_msg = e.what(); \
130 } catch (const std::runtime_error& e) { \
131 obptc_exc_type = Opm::ExceptionType::RUNTIME_ERROR; \
132 obptc_exc_msg = e.what(); \
133 } catch (const std::invalid_argument& e) { \
134 obptc_exc_type = Opm::ExceptionType::INVALID_ARGUMENT; \
135 obptc_exc_msg = e.what(); \
136 } catch (const std::logic_error& e) { \
137 obptc_exc_type = Opm::ExceptionType::LOGIC_ERROR; \
138 obptc_exc_msg = e.what(); \
139 } catch (const std::exception& e) { \
140 obptc_exc_type = Opm::ExceptionType::DEFAULT; \
141 obptc_exc_msg = e.what(); \
143 obptc_exc_type = Opm::ExceptionType::DEFAULT; \
144 obptc_exc_msg = "Unknown exception was thrown"; \
151 #define OPM_END_PARALLEL_TRY_CATCH(prefix, comm) \
153 OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg);\
154 checkForExceptionsAndThrow(obptc_exc_type, \
155 prefix + obptc_exc_msg, comm);
161 #define OPM_END_PARALLEL_TRY_CATCH_LOG(obptc_logger, obptc_prefix, obptc_output, comm)\
163 OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg); \
164 logAndCheckForExceptionsAndThrow(obptc_logger, obptc_exc_type, \
165 obptc_prefix + obptc_exc_msg, obptc_output, comm);
Definition: DeferredLogger.hpp:57
void logMessages()
Log all messages to the OpmLog backends, and clear the message container.
Definition: DeferredLogger.cpp:85
void clearMessages()
Clear the message container without logging them.
Definition: DeferredLogger.cpp:93
Opm::DeferredLogger gatherDeferredLogger(const Opm::DeferredLogger &local_deferredlogger, Opm::Parallel::Communication)
Create a global log combining local logs.
Definition: gatherDeferredLogger.cpp:168