21#ifndef OPM_DEFERREDLOGGINGERRORHELPERS_HPP
22#define OPM_DEFERREDLOGGINGERRORHELPERS_HPP
24#include <opm/common/Exceptions.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_); \
61#define OPM_DEFLOG_PROBLEM(Exception, message, deferred_logger) \
63 std::string oss_ = std::string{"["} + __FILE__ + ":" + \
64 std::to_string(__LINE__) + "] " + \
66 deferred_logger.problem(oss_); \
67 throw Exception(oss_); \
74 const std::string& message,
77 auto global_exc = comm.max(exc_type);
83 throw std::runtime_error(message);
86 throw std::invalid_argument(message);
89 throw Opm::NumericalProblem(message);
93 throw std::logic_error(message);
96 throw std::logic_error(message);
105 const std::string& message,
108 _throw(exc_type, message, comm);
113 const std::string& message,
114 const bool terminal_output,
119 deferred_logger.
error(
"[Exception on rank " +
std::to_string(comm.rank()) +
"]: " + message);
123 if (terminal_output) {
130 _throw(exc_type, message, comm);
135 const std::string& message,
136 const bool terminal_output,
145 if (terminal_output) {
152 _throw(exc_type, message, comm);
158#define OPM_BEGIN_PARALLEL_TRY_CATCH() \
159std::string obptc_exc_msg; \
160auto obptc_exc_type = Opm::ExceptionType::NONE; \
166#define OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, \
168catch (const Opm::NumericalProblem& e){ \
169 obptc_exc_type = Opm::ExceptionType::NUMERICAL_ISSUE; \
170 obptc_exc_msg = e.what(); \
171} catch (const std::runtime_error& e) { \
172 obptc_exc_type = Opm::ExceptionType::RUNTIME_ERROR; \
173 obptc_exc_msg = e.what(); \
174} catch (const std::invalid_argument& e) { \
175 obptc_exc_type = Opm::ExceptionType::INVALID_ARGUMENT; \
176 obptc_exc_msg = e.what(); \
177} catch (const std::logic_error& e) { \
178 obptc_exc_type = Opm::ExceptionType::LOGIC_ERROR; \
179 obptc_exc_msg = e.what(); \
180} catch (const std::exception& e) { \
181 obptc_exc_type = Opm::ExceptionType::DEFAULT; \
182 obptc_exc_msg = e.what(); \
184 obptc_exc_type = Opm::ExceptionType::DEFAULT; \
185 obptc_exc_msg = "Unknown exception was thrown"; \
192#define OPM_END_PARALLEL_TRY_CATCH(prefix, comm) \
194OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg);\
195checkForExceptionsAndThrow(obptc_exc_type, \
196 prefix + obptc_exc_msg, comm);
202#define OPM_END_PARALLEL_TRY_CATCH_LOG(obptc_logger, obptc_prefix, obptc_output, comm)\
204OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg); \
205logAndCheckForExceptionsAndThrow(obptc_logger, obptc_exc_type, \
206 obptc_prefix + obptc_exc_msg, obptc_output, comm);
void logAndCheckForProblemsAndThrow(Opm::DeferredLogger &deferred_logger, Opm::ExceptionType::ExcEnum exc_type, const std::string &message, const bool terminal_output, Opm::Parallel::Communication comm)
Definition: DeferredLoggingErrorHelpers.hpp:133
void logAndCheckForExceptionsAndThrow(Opm::DeferredLogger &deferred_logger, Opm::ExceptionType::ExcEnum exc_type, const std::string &message, const bool terminal_output, Opm::Parallel::Communication comm)
Definition: DeferredLoggingErrorHelpers.hpp:111
void checkForExceptionsAndThrow(Opm::ExceptionType::ExcEnum exc_type, const std::string &message, Opm::Parallel::Communication comm)
Definition: DeferredLoggingErrorHelpers.hpp:104
Definition: DeferredLogger.hpp:57
void problem(const std::string &tag, const std::string &message)
void clearMessages()
Clear the message container without logging them.
void error(const std::string &tag, const std::string &message)
ExcEnum
Definition: DeferredLogger.hpp:45
@ NONE
Definition: DeferredLogger.hpp:46
@ INVALID_ARGUMENT
Definition: DeferredLogger.hpp:48
@ RUNTIME_ERROR
Definition: DeferredLogger.hpp:47
@ LOGIC_ERROR
Definition: DeferredLogger.hpp:49
@ DEFAULT
Definition: DeferredLogger.hpp:50
@ NUMERICAL_ISSUE
Definition: DeferredLogger.hpp:51
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Opm::DeferredLogger gatherDeferredLogger(const Opm::DeferredLogger &local_deferredlogger, Parallel::Communication communicator)
Create a global log combining local logs.
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)