From 275525af44d5c047b16c581b1bd71c53dceeab1d Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 23 Jun 2025 18:48:05 +0200 Subject: [PATCH] CoreFoundation: extend cf_runtime_error to support user message Signed-off-by: Simon Rozman --- include/MacStd/CoreFoundation.hpp | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/include/MacStd/CoreFoundation.hpp b/include/MacStd/CoreFoundation.hpp index 134bf83..692e8f2 100644 --- a/include/MacStd/CoreFoundation.hpp +++ b/include/MacStd/CoreFoundation.hpp @@ -65,6 +65,26 @@ namespace macstd { { } + /// + /// Constructs an exception + /// + /// \param[in] error Core Foundation error + /// \param[in] msg Error message + /// + cf_runtime_error(CFErrorRef error, const std::string& msg) : + num_runtime_error(CFErrorGetCode(error), msg + ": " + message(error)), + m_error(error) + { + } + + /// + /// Constructs an exception + /// + /// \param[in] error Core Foundation error + /// \param[in] msg Error message + /// + cf_runtime_error(CFErrorRef error, const char* msg) : cf_runtime_error(error, std::string(msg)) {} + /// /// Constructs an exception /// @@ -76,6 +96,26 @@ namespace macstd { { } + /// + /// Constructs an exception + /// + /// \param[in] error Core Foundation error + /// \param[in] msg Error message + /// + cf_runtime_error(cferror&& error, const std::string& msg) : + num_runtime_error(CFErrorGetCode(error), msg + ": " + message(error)), + m_error(std::move(error)) + { + } + + /// + /// Constructs an exception + /// + /// \param[in] error Core Foundation error + /// \param[in] msg Error message + /// + cf_runtime_error(cferror&& error, const char* msg) : cf_runtime_error(std::move(error), std::string(msg)) {} + CFErrorRef cferror() const noexcept { return m_error; } protected: