diff --git a/src/application.cpp b/src/application.cpp index ecd4f9c..b72335a 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -37,7 +37,7 @@ Application::Logger::Logger(std::string name) { cur_monitor_ = app->GetMonitor(name); cur_monitor_->Enter(); } else { - throw NotFoundError("Monitor " + name); + throw NotFoundError("Logger", "Monitor " + name); } } @@ -157,7 +157,7 @@ std::string Application::FindInputFile(const std::string& name) { if (fin) { return full_name; } else { - throw NotFoundError("Input file " + name); + throw NotFoundError("FindInputFile", "Input file " + name); } } } @@ -169,7 +169,7 @@ std::string Application::FindInputFile(const std::string& name) { if (fin) { return name; } else { - throw NotFoundError("Input file " + name); + throw NotFoundError("FindInputFile", "Input file " + name); } } diff --git a/src/exceptions.cpp b/src/exceptions.cpp index 1f0efc5..c6b2d8d 100644 --- a/src/exceptions.cpp +++ b/src/exceptions.cpp @@ -48,3 +48,11 @@ std::string IndexError::GetMessage() const { arrayName_.c_str(), m_, mmax_); return buf; } + +std::string RuntimeError::GetMessage() const { + char buf[160]; + snprintf(buf, sizeof(buf), + "RuntimeError: Expect %f but get %f for variable %s.", + expect_, val_, var_.c_str()); + return buf; +} diff --git a/src/exceptions.hpp b/src/exceptions.hpp index 733eb66..7a19ef6 100644 --- a/src/exceptions.hpp +++ b/src/exceptions.hpp @@ -146,4 +146,21 @@ class InvalidValueError : public ExceptionBase { virtual std::string GetClass() const { return "InvalidValueError"; } }; +//! An general runtime error +class RuntimeError : public ExceptionBase { + public: + //! @param func Name of the unimplemented function, such as + //! `ClassName::functionName` + RuntimeError(const std::string& func, std::string const& var, + double expect, double val) + : ExceptionBase(func), var_(var), expect_(expect), val_(val) {} + + virtual std::string GetMessage() const; + virtual std::string GetClass() const { return "RuntimeError"; } + protected: + std::string var_; + double expect_; + double val_; +}; + #endif // SRC_EXCEPTIONS_HPP_