diff --git a/SDL2pp/Exception.cc b/SDL2pp/Exception.cc index f41e420..8386974 100644 --- a/SDL2pp/Exception.cc +++ b/SDL2pp/Exception.cc @@ -1,6 +1,6 @@ /* libSDL2pp - C++11 bindings/wrapper for SDL2 - Copyright (C) 2013-2015 Dmitry Marakasov + Copyright (C) 2013-2016 Dmitry Marakasov This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -25,19 +25,22 @@ namespace SDL2pp { +std::string Exception::make_what(const char* function, const char* sdl_error) { + std::string tmp(function); + tmp += " failed: "; + tmp += sdl_error; + return tmp; +} + Exception::Exception(const char* function) - : sdl_function_(function), - sdl_error_(SDL_GetError()), - what_(sdl_function_ + " failed: " + sdl_error_) { + : std::runtime_error(make_what(function, SDL_GetError())), + sdl_function_(function), + sdl_error_(SDL_GetError()) { } Exception::~Exception() noexcept { } -const char* Exception::what() const noexcept { - return what_.c_str(); -} - std::string Exception::GetSDLFunction() const { return sdl_function_; } diff --git a/SDL2pp/Exception.hh b/SDL2pp/Exception.hh index 7fb8a25..356e109 100644 --- a/SDL2pp/Exception.hh +++ b/SDL2pp/Exception.hh @@ -1,6 +1,6 @@ /* libSDL2pp - C++11 bindings/wrapper for SDL2 - Copyright (C) 2013-2015 Dmitry Marakasov + Copyright (C) 2013-2016 Dmitry Marakasov This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -23,7 +23,7 @@ #define SDL2PP_EXCEPTION_HH #include -#include +#include namespace SDL2pp { @@ -66,11 +66,13 @@ namespace SDL2pp { /// \endcode /// //////////////////////////////////////////////////////////// -class Exception : public std::exception { +class Exception : public std::runtime_error { private: std::string sdl_function_; ///< SDL function which caused an error std::string sdl_error_; ///< SDL error string - std::string what_; ///< User-readable message + +private: + static std::string make_what(const char* sdl_function, const char* sdl_error); public: //////////////////////////////////////////////////////////// @@ -93,14 +95,6 @@ public: //////////////////////////////////////////////////////////// virtual ~Exception() noexcept; - //////////////////////////////////////////////////////////// - /// \brief Get explanatory string - /// - /// \returns Explanatory string stored in the exception object - /// - //////////////////////////////////////////////////////////// - const char* what() const noexcept; - //////////////////////////////////////////////////////////// /// \brief Get name of SDL function which caused an error ///