From 8a27fa9c617533e76673ce61a65e2ba869b52208 Mon Sep 17 00:00:00 2001 From: B Stack Date: Mon, 31 Aug 2020 20:07:13 -0400 Subject: add upstream 11.1 --- zen/sys_error.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'zen/sys_error.h') diff --git a/zen/sys_error.h b/zen/sys_error.h index 01df17ab..f4b867be 100644 --- a/zen/sys_error.h +++ b/zen/sys_error.h @@ -7,11 +7,11 @@ #ifndef SYS_ERROR_H_3284791347018951324534 #define SYS_ERROR_H_3284791347018951324534 -//#include #include "scope_guard.h" // #include "utf.h" //not used by this header, but the "rest of the world" needs it! #include "i18n.h" // + #include #include @@ -24,6 +24,7 @@ ErrorCode getLastError(); std::wstring formatSystemError(const std::string& functionName, const std::wstring& errorCode, const std::wstring& errorMsg); std::wstring formatSystemError(const std::string& functionName, ErrorCode ec); + std::wstring formatGlibError(const std::string& functionName, GError* error); //A low-level exception class giving (non-translated) detail information only - same conceptional level like "GetLastError()"! @@ -45,6 +46,12 @@ private: do { const ErrorCode ecInternal = getLastError(); throw SysError(formatSystemError(functionName, ecInternal)); } while (false) +/* Example: ASSERT_SYSERROR(expr); + + Equivalent to: + if (!expr) + throw zen::SysError(L"Assertion failed: \"expr\""); */ +#define ASSERT_SYSERROR(expr) ASSERT_SYSERROR_IMPL(expr, #expr) //throw SysError @@ -61,6 +68,17 @@ std::wstring getSystemErrorDescription(ErrorCode ec); //return empty string on e std::wstring getSystemErrorDescription(long long) = delete; + + +namespace impl +{ +inline bool validateBool(bool b) { return b; } +inline bool validateBool(void* b) { return b; } +bool validateBool(int) = delete; //catch unintended bool conversions, e.g. HRESULT +} +#define ASSERT_SYSERROR_IMPL(expr, exprStr) \ + { if (!impl::validateBool(expr)) \ + throw zen::SysError(L"Assertion failed: \"" L ## exprStr L"\""); } } #endif //SYS_ERROR_H_3284791347018951324534 -- cgit