21#ifndef OPM_DEFERREDLOGGINGERRORHELPERS_HPP
22#define OPM_DEFERREDLOGGINGERRORHELPERS_HPP
24#include <opm/common/Exceptions.hpp>
26#include <opm/simulators/utils/DeferredLogger.hpp>
27#include <opm/simulators/utils/gatherDeferredLogger.hpp>
29#include <opm/simulators/utils/ParallelCommunication.hpp>
45#define OPM_DEFLOG_THROW(Exception, message, deferred_logger) \
47 std::string oss_ = std::string{"["} + __FILE__ + ":" + \
48 std::to_string(__LINE__) + "] " + \
50 deferred_logger.error(oss_); \
51 throw Exception(oss_); \
56void _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:
74 case Opm::ExceptionType::DEFAULT:
75 case Opm::ExceptionType::LOGIC_ERROR:
76 throw std::logic_error(message);
79 throw std::logic_error(message);
87inline 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() \
118std::string obptc_exc_msg; \
119auto obptc_exc_type = Opm::ExceptionType::NONE; \
125#define OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, \
127catch (const Opm::NumericalProblem& 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) \
153OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg);\
154checkForExceptionsAndThrow(obptc_exc_type, \
155 prefix + obptc_exc_msg, comm);
161#define OPM_END_PARALLEL_TRY_CATCH_LOG(obptc_logger, obptc_prefix, obptc_output, comm)\
163OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg); \
164logAndCheckForExceptionsAndThrow(obptc_logger, obptc_exc_type, \
165 obptc_prefix + obptc_exc_msg, obptc_output, comm);
Definition AquiferInterface.hpp:35
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