From 648794b0bb270fffb3e8aaea138c09f3f164164c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Mon, 25 Nov 2019 07:46:21 +0100 Subject: [PATCH] Exception ctor in cpp to reduce codesize --- libsrc/core/exception.cpp | 20 ++++++++++++++++++++ libsrc/core/exception.hpp | 9 ++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/libsrc/core/exception.cpp b/libsrc/core/exception.cpp index a1909a7c..a1ed26f1 100644 --- a/libsrc/core/exception.cpp +++ b/libsrc/core/exception.cpp @@ -18,6 +18,26 @@ namespace ngcore { + + + Exception :: Exception(const std::string& s) + : m_what(s) {} + + Exception :: Exception(const char* s) + : m_what(s) {} + + + void ThrowException(const std::string & s) + { + throw Exception (s); + } + + void ThrowException(const char * s) + { + throw Exception (s); + } + + namespace detail { static int exec(std::string cmd, std::string & out) { diff --git a/libsrc/core/exception.hpp b/libsrc/core/exception.hpp index 406a4eb2..bfec7a75 100644 --- a/libsrc/core/exception.hpp +++ b/libsrc/core/exception.hpp @@ -31,8 +31,8 @@ namespace ngcore Exception() = default; Exception(const Exception&) = default; Exception(Exception&&) = default; - Exception(const std::string& s) : m_what(s) {} - Exception(const char* s) : m_what(s) {} + Exception(const std::string& s); // : m_what(s) {} + Exception(const char* s); // : m_what(s) {} ~Exception() override = default; Exception& operator =(const Exception&) = default; @@ -49,7 +49,10 @@ namespace ngcore /// implement virtual function of std::exception const char* what() const noexcept override { return m_what.c_str(); } }; - + + NGCORE_API void ThrowException(const std::string & s); + NGCORE_API void ThrowException(const char * s); + // Out of Range exception class NGCORE_API RangeException : public Exception {