From 524f7511af0dbafefeed8b0f2645d9388fd79ed8 Mon Sep 17 00:00:00 2001 From: Andrea Blankenstijn Date: Sat, 14 Aug 2021 09:24:19 +0200 Subject: [PATCH] exception: default 'what' to 'unknown' --- inc/basic_widgets/core/error_helper.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/inc/basic_widgets/core/error_helper.hpp b/inc/basic_widgets/core/error_helper.hpp index 1cbfebb..bf1e91a 100644 --- a/inc/basic_widgets/core/error_helper.hpp +++ b/inc/basic_widgets/core/error_helper.hpp @@ -7,10 +7,10 @@ namespace bwidgets { template - 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) what = w.empty() ? SDL_GetError() : w; + if constexpr (std::is_same_v) what = w == "unknown" ? SDL_GetError() : w; else what = w; if (ptr == nullptr) throw E(what); @@ -19,14 +19,14 @@ namespace bwidgets template inline auto success_or_throw( - T code, const std::string& w = "", + T code, const std::string& w = "unknown", std::function 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) { if (code <= 0) throw E(what); } - else if (!success(code)) throw E(what); + else if (success(code)) throw E(what); return code; }