CoreFoundation: extend cf_runtime_error to support user message

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2025-06-23 18:48:05 +02:00
parent 52a076e105
commit 275525af44

View File

@ -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<CFIndex>(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 /// 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<CFIndex>(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; } CFErrorRef cferror() const noexcept { return m_error; }
protected: protected: