From a97a2ef24d9b911ebe2f3ca23e4d6f9758704170 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 28 Jan 2026 22:05:02 +0100 Subject: [PATCH] [client,sdl] refactor exception class --- client/SDL/SDL3/sdl_freerdp.cpp | 43 +++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/client/SDL/SDL3/sdl_freerdp.cpp b/client/SDL/SDL3/sdl_freerdp.cpp index 678547d88..9dc1c9416 100644 --- a/client/SDL/SDL3/sdl_freerdp.cpp +++ b/client/SDL/SDL3/sdl_freerdp.cpp @@ -70,6 +70,37 @@ #define SDL_TAG CLIENT_TAG("SDL") #endif +class ErrorMsg : public std::exception +{ + public: + ErrorMsg(int rc, Uint32 type, const std::string& msg); + + [[nodiscard]] int rc() const; + [[nodiscard]] const char* what() const noexcept override; + + private: + int _rc; + Uint32 _type; + std::string _msg; + std::string _buffer; +}; +const char* ErrorMsg::what() const noexcept +{ + return _buffer.c_str(); +} + +int ErrorMsg::rc() const +{ + return _rc; +} + +ErrorMsg::ErrorMsg(int rc, Uint32 type, const std::string& msg) : _rc(rc), _type(type), _msg(msg) +{ + std::stringstream ss; + ss << _msg << " {" << sdl::utils::toString(_type) << "}"; + _buffer = ss.str(); +} + static void sdl_term_handler([[maybe_unused]] int signum, [[maybe_unused]] const char* signame, [[maybe_unused]] void* context) { @@ -81,13 +112,6 @@ static void sdl_term_handler([[maybe_unused]] int signum, [[maybe_unused]] const int rc = -1; WINPR_ASSERT(sdl); - struct ErrorMsg - { - int rc; - Uint32 type; - std::string msg; - }; - try { while (!sdl->shallAbort()) @@ -230,9 +254,8 @@ static void sdl_term_handler([[maybe_unused]] int signum, [[maybe_unused]] const } catch (ErrorMsg& msg) { - WLog_Print(sdl->getWLog(), WLOG_ERROR, "[exception] %s {%s}", msg.msg.c_str(), - sdl::utils::toString(msg.type).c_str()); - rc = msg.rc; + WLog_Print(sdl->getWLog(), WLOG_ERROR, "[exception] %s", msg.what()); + rc = msg.rc(); } return rc;