Exception ctor in cpp to reduce codesize

This commit is contained in:
Joachim Schöberl 2019-11-25 07:46:21 +01:00
parent 0ff62c6549
commit 648794b0bb
2 changed files with 26 additions and 3 deletions

View File

@ -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) {

View File

@ -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
{