21#ifndef OPM_DEFERREDLOGGINGERRORHELPERS_HPP
22#define OPM_DEFERREDLOGGINGERRORHELPERS_HPP
24#include <dune/istl/istlexception.hh>
26#include <opm/common/Exceptions.hpp>
47#define OPM_DEFLOG_THROW(Exception, message, deferred_logger) \
49 std::string oss_ = std::string{"["} + __FILE__ + ":" + \
50 std::to_string(__LINE__) + "] " + \
52 deferred_logger.error(oss_); \
53 throw Exception(oss_); \
63#define OPM_DEFLOG_PROBLEM(Exception, message, deferred_logger) \
65 std::string oss_ = std::string{"["} + __FILE__ + ":" + \
66 std::to_string(__LINE__) + "] " + \
68 deferred_logger.problem(oss_); \
69 throw Exception(oss_); \
76 const std::string& message,
79 auto global_exc = comm.max(exc_type);
85 throw std::runtime_error(message);
88 throw std::invalid_argument(message);
91 throw Opm::NumericalProblem(message);
95 throw std::logic_error(message);
98 throw std::logic_error(message);
107 const std::string& message,
110 _throw(exc_type, message, comm);
115 const std::string& message,
116 const bool terminal_output,
121 deferred_logger.
error(
"[Exception on rank " +
std::to_string(comm.rank()) +
"]: " + message);
125 if (terminal_output) {
132 _throw(exc_type, message, comm);
137 const std::string& message,
138 const bool terminal_output,
147 if (terminal_output) {
154 _throw(exc_type, message, comm);
160#define OPM_BEGIN_PARALLEL_TRY_CATCH() \
161std::string obptc_exc_msg; \
162auto obptc_exc_type = Opm::ExceptionType::NONE; \
168#define OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, \
170catch (const Opm::NumericalProblem& e){ \
171 obptc_exc_type = Opm::ExceptionType::NUMERICAL_ISSUE; \
172 obptc_exc_msg = e.what(); \
173} catch (const Dune::MatrixBlockError& e) { \
174 obptc_exc_type = Opm::ExceptionType::NUMERICAL_ISSUE; \
175 obptc_exc_msg = e.what(); \
176} catch (const std::runtime_error& e) { \
177 obptc_exc_type = Opm::ExceptionType::RUNTIME_ERROR; \
178 obptc_exc_msg = e.what(); \
179} catch (const std::invalid_argument& e) { \
180 obptc_exc_type = Opm::ExceptionType::INVALID_ARGUMENT; \
181 obptc_exc_msg = e.what(); \
182} catch (const std::logic_error& e) { \
183 obptc_exc_type = Opm::ExceptionType::LOGIC_ERROR; \
184 obptc_exc_msg = e.what(); \
185} catch (const std::exception& e) { \
186 obptc_exc_type = Opm::ExceptionType::DEFAULT; \
187 obptc_exc_msg = e.what(); \
189 obptc_exc_type = Opm::ExceptionType::DEFAULT; \
190 obptc_exc_msg = "Unknown exception was thrown"; \
197#define OPM_END_PARALLEL_TRY_CATCH(prefix, comm) \
199OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg);\
200checkForExceptionsAndThrow(obptc_exc_type, \
201 prefix + obptc_exc_msg, comm);
207#define OPM_END_PARALLEL_TRY_CATCH_LOG(obptc_logger, obptc_prefix, obptc_output, comm)\
209OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg); \
210logAndCheckForExceptionsAndThrow(obptc_logger, obptc_exc_type, \
211 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:135
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:113
void checkForExceptionsAndThrow(Opm::ExceptionType::ExcEnum exc_type, const std::string &message, Opm::Parallel::Communication comm)
Definition: DeferredLoggingErrorHelpers.hpp:106
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)