Add and use OPM_DEFLOG_PROBLEM macro.

This should replace OPM_DEFLOG_THROW in places where the problem
category is more appropriate than the error category.

In this commit, uses of OPM_DEFLOG_THROW have been replaced whenever
the exception class used was NumericalProblem.
This commit is contained in:
Atgeirr Flø Rasmussen
2023-11-08 15:16:17 +01:00
parent 895074eb3b
commit 749ea93e24
5 changed files with 30 additions and 13 deletions

View File

@@ -32,7 +32,7 @@
#include <exception>
#include <stdexcept>
// Macro to throw an exception.
// Macro to log an error and throw an exception.
// Inspired by ErrorMacros.hpp in opm-common.
// NOTE: For this macro to work, the
// exception class must exhibit a constructor with the signature
@@ -51,6 +51,23 @@
throw Exception(oss_); \
} while (false)
// Macro to log a problem and throw an exception.
// Idenitical to OPM_DEFLOG_THROW() except for using
// the "problem" category instead of "error" for the
// log message. The Exception argument will typically
// be NumericalProblem.
//
// Usage: OPM_DEFLOG_PROBLEM(ExceptionClass, "Error message", DeferredLogger);
#define OPM_DEFLOG_PROBLEM(Exception, message, deferred_logger) \
do { \
std::string oss_ = std::string{"["} + __FILE__ + ":" + \
std::to_string(__LINE__) + "] " + \
message; \
deferred_logger.problem(oss_); \
throw Exception(oss_); \
} while (false)
namespace {
void _throw(Opm::ExceptionType::ExcEnum exc_type,