Skip to content
Snippets Groups Projects
Commit 3996dc6c authored by Santiago Ospina De Los Ríos's avatar Santiago Ospina De Los Ríos
Browse files

Throw RangeError exception in bounds check instead of using DUNE_THROW

parent 88486b92
Branches
Tags
No related merge requests found
Pipeline #74554 waiting for manual action
......@@ -21,9 +21,11 @@
namespace Dune::Impl
{
void boundCheckThrow(std::string_view func, std::string_view file, int line)
std::string boundCheckString(std::string_view func, std::string_view file, int line)
{
DUNE_THROW(Dune::RangeError, "\nDUNE_ASSERT_BOUNDS [" << func << ":" << file << ":" << line << "]: Index out of bounds.");
std::ostringstream os;
os << "Dune::RangeError [" << func << ":" << file << ":" << line << "]: Index out of bounds.";
return os.str();
}
}
......@@ -38,7 +40,7 @@ namespace Dune::Impl
#define DUNE_ASSERT_BOUNDS(cond) \
do { \
if (!(cond)) \
Dune::Impl::boundCheckThrow(__func__, __FILE__, __LINE__); \
throw Dune::RangeError{Dune::Impl::boundCheckString(__func__, __FILE__, __LINE__)};\
} while (false)
#else
......
......@@ -19,6 +19,12 @@ namespace Dune {
if (_hook != 0) _hook->operator()();
}
Exception::Exception (std::string && msg)
: Exception{}
{
message(std::move(msg));
}
void Exception::registerHook (ExceptionHook * hook)
{
_hook = hook;
......@@ -34,6 +40,11 @@ namespace Dune {
_message = msg;
}
void Exception::message(std::string&& msg)
{
_message = std::move(msg);
}
const char* Exception::what() const noexcept
{
return _message.data();
......
......@@ -96,7 +96,9 @@ namespace Dune {
{
public:
Exception ();
void message(const std::string &msg); //!< store string in internal message buffer
Exception (std::string &&msg);
[[deprecated]] void message(const std::string &msg); //!< store string in internal message buffer
void message(std::string&& msg); //!< store string in internal message buffer
const char* what() const noexcept override; //!< output internal message buffer
static void registerHook (ExceptionHook * hook); //!< add a functor which is called before a Dune::Exception is emitted (see Dune::ExceptionHook) \see Dune::ExceptionHook
static void clearHook (); //!< remove all hooks
......@@ -228,7 +230,9 @@ namespace Dune {
- could not write file
- could not connect to remote socket
*/
class IOError : public Exception {};
class IOError : public Exception {
using Exception::Exception;
};
/*! \brief Default exception class for mathematical errors
......@@ -238,7 +242,9 @@ namespace Dune {
- matrix not invertible
- not convergent
*/
class MathError : public Exception {};
class MathError : public Exception {
using Exception::Exception;
};
/*! \brief Default exception class for range errors
......@@ -251,7 +257,9 @@ namespace Dune {
with only three non zero entries per row
*/
class RangeError : public Exception {};
class RangeError : public Exception {
using Exception::Exception;
};
/*! \brief Default exception for dummy implementations
......@@ -260,7 +268,9 @@ namespace Dune {
- that have to be implemented but should never be called
- that are missing
*/
class NotImplemented : public Exception {};
class NotImplemented : public Exception {
using Exception::Exception;
};
/*! \brief Default exception class for OS errors
......@@ -268,23 +278,31 @@ namespace Dune {
error.
*/
class SystemError : public Exception {};
class SystemError : public Exception {
using Exception::Exception;
};
/*! \brief Default exception if memory allocation fails
*/
class OutOfMemoryError : public SystemError {};
class OutOfMemoryError : public SystemError {
using SystemError::SystemError;
};
/*! \brief Default exception if a function was called while
the object is not in a valid state for that function.
*/
class InvalidStateException : public Exception {};
class InvalidStateException : public Exception {
using Exception::Exception;
};
/*! \brief Default exception if an error in the parallel
communication of the program occurred
\ingroup ParallelCommunication
*/
class ParallelError : public Exception {};
class ParallelError : public Exception {
using Exception::Exception;
};
} // end namespace
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment