mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 10:55:57 -04:00
Derive Exception from std::runtime_error instead of std::exception
Apart from placing Exception into right place in exception class hierarchy this change allows more memory usage optimizations. Fixes #68
This commit is contained in:
parent
cc01d37769
commit
9f8a72db9c
@ -1,6 +1,6 @@
|
||||
/*
|
||||
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
|
||||
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_;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
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
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@ -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
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user