diff options
-rw-r--r-- | src/core/common/Exceptions.cpp | 16 | ||||
-rw-r--r-- | src/core/common/Exceptions.hpp | 26 |
2 files changed, 15 insertions, 27 deletions
diff --git a/src/core/common/Exceptions.cpp b/src/core/common/Exceptions.cpp index e368b5a..caba7cc 100644 --- a/src/core/common/Exceptions.cpp +++ b/src/core/common/Exceptions.cpp @@ -22,21 +22,5 @@ namespace ousia { -/* Class LoggableException */ - -std::string LoggableException::formatMessage(const std::string &msg, - const SourceLocation &loc) -{ - std::stringstream ss; - ss << "error "; - if (loc.hasLine()) { - ss << "at line " << loc.line << ", "; - if (loc.hasColumn()) { - ss << "column " << loc.column << " "; - } - } - ss << "with message: " << msg; - return ss.str(); -} } diff --git a/src/core/common/Exceptions.hpp b/src/core/common/Exceptions.hpp index 2a88427..0be33b3 100644 --- a/src/core/common/Exceptions.hpp +++ b/src/core/common/Exceptions.hpp @@ -77,14 +77,6 @@ public: * makes it simple to handle non-recoverable errors in the code. */ class LoggableException : public OusiaException { -private: - /** - * Function used internally to build the formated message that should be - * reported to the runtime environment. - */ - static std::string formatMessage(const std::string &msg, - const SourceLocation &loc); - public: /** * Reported error message. @@ -104,7 +96,7 @@ public: */ LoggableException(std::string msg, SourceLocation loc = SourceLocation{}) - : OusiaException(formatMessage(msg, loc)), + : OusiaException(msg), msg(std::move(msg)), loc(std::move(loc)) { @@ -128,15 +120,27 @@ public: * Constructor of LoggableException for arbitrary position objects. * * @param msg is the actual log message. - * @param loc is a reference to a variable with position and context data. + * @param loc is a reference to a variable with location data. */ template <class LocationType> - LoggableException(std::string msg, LocationType &loc) + LoggableException(std::string msg, const LocationType &loc) : LoggableException(std::move(msg), loc.getLocation()) { } /** + * Constructor of LoggableException for arbitrary position objects. + * + * @param msg is the actual log message. + * @param loc is a pointe to a variable with location data. + */ + template <class LocationType> + LoggableException(std::string msg, const LocationType *loc) + : LoggableException(std::move(msg), loc->getLocation()) + { + } + + /** * Returns the position at which the exception occured in the text. * * @return the position descriptor. |