Merge branch 'issue-68'

This commit is contained in:
Dmitry Marakasov 2016-05-09 12:32:13 +03:00
commit 042d6f25b2
2 changed files with 17 additions and 20 deletions

View File

@ -1,6 +1,6 @@
/* /*
libSDL2pp - C++11 bindings/wrapper for SDL2 libSDL2pp - C++11 bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru> Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -25,19 +25,22 @@
namespace SDL2pp { 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) Exception::Exception(const char* function)
: sdl_function_(function), : std::runtime_error(make_what(function, SDL_GetError())),
sdl_error_(SDL_GetError()), sdl_function_(function),
what_(sdl_function_ + " failed: " + sdl_error_) { sdl_error_(SDL_GetError()) {
} }
Exception::~Exception() noexcept { Exception::~Exception() noexcept {
} }
const char* Exception::what() const noexcept {
return what_.c_str();
}
std::string Exception::GetSDLFunction() const { std::string Exception::GetSDLFunction() const {
return sdl_function_; return sdl_function_;
} }

View File

@ -1,6 +1,6 @@
/* /*
libSDL2pp - C++11 bindings/wrapper for SDL2 libSDL2pp - C++11 bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru> Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -23,7 +23,7 @@
#define SDL2PP_EXCEPTION_HH #define SDL2PP_EXCEPTION_HH
#include <string> #include <string>
#include <exception> #include <stdexcept>
namespace SDL2pp { namespace SDL2pp {
@ -66,11 +66,13 @@ namespace SDL2pp {
/// \endcode /// \endcode
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
class Exception : public std::exception { class Exception : public std::runtime_error {
private: private:
std::string sdl_function_; ///< SDL function which caused an error std::string sdl_function_; ///< SDL function which caused an error
std::string sdl_error_; ///< SDL error string 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: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -93,14 +95,6 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual ~Exception() noexcept; 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 /// \brief Get name of SDL function which caused an error
/// ///