exception: default 'what' to 'unknown'
This commit is contained in:
parent
7c5277dabd
commit
524f7511af
1 changed files with 5 additions and 5 deletions
|
@ -7,10 +7,10 @@
|
|||
namespace bwidgets
|
||||
{
|
||||
template<Exception E, typename T>
|
||||
inline auto ptr_or_throw(T* ptr, const std::string& w = "") -> T*
|
||||
inline auto ptr_or_throw(T* ptr, const std::string& w = "unknown") -> T*
|
||||
{
|
||||
std::string what;
|
||||
if constexpr (std::is_same_v<E, SDLError>) what = w.empty() ? SDL_GetError() : w;
|
||||
if constexpr (std::is_same_v<E, SDLError>) what = w == "unknown" ? SDL_GetError() : w;
|
||||
else what = w;
|
||||
|
||||
if (ptr == nullptr) throw E(what);
|
||||
|
@ -19,14 +19,14 @@ namespace bwidgets
|
|||
|
||||
template<Exception E, typename T>
|
||||
inline auto success_or_throw(
|
||||
T code, const std::string& w = "",
|
||||
T code, const std::string& w = "unknown",
|
||||
std::function<bool(T)> success = [](T code) { return code == 0; }) -> T
|
||||
{
|
||||
std::string what {w.empty() ? SDL_GetError() : w};
|
||||
std::string what {w == "unknown" ? SDL_GetError() : w};
|
||||
if constexpr (std::is_same_v<E, SDLError>) {
|
||||
if (code <= 0) throw E(what);
|
||||
}
|
||||
else if (!success(code)) throw E(what);
|
||||
else if (success(code)) throw E(what);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue