exception: default 'what' to 'unknown'

This commit is contained in:
Andrea Blankenstijn 2021-08-14 09:24:19 +02:00
parent 7c5277dabd
commit 524f7511af
1 changed files with 5 additions and 5 deletions

View File

@ -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;
}