From 94db751716dd2851f99b5c4c2981da1d1f4780f8 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 2 Oct 2015 14:53:20 +0200 Subject: 6.11 --- zen/sys_error.h | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'zen/sys_error.h') diff --git a/zen/sys_error.h b/zen/sys_error.h index 8afab138..9cfc762f 100644 --- a/zen/sys_error.h +++ b/zen/sys_error.h @@ -35,7 +35,7 @@ typedef int ErrorCode; ErrorCode getLastError(); std::wstring formatSystemError(const std::wstring& functionName, ErrorCode lastError); - +std::wstring formatSystemError(const std::wstring& functionName, ErrorCode lastError, const std::wstring& lastErrorMsg); //A low-level exception class giving (non-translated) detail information only - same conceptional level like "GetLastError()"! class SysError @@ -75,11 +75,7 @@ std::wstring formatSystemError(const std::wstring& functionName, ErrorCode lastE { const ErrorCode currentError = getLastError(); //not necessarily == lastError - //determine error code if none was specified - if (lastError == 0) - lastError = currentError; - - std::wstring output = replaceCpy(_("Error Code %x:"), L"%x", numberTo(lastError)); + std::wstring lastErrorMsg; #ifdef ZEN_WIN ZEN_ON_SCOPE_EXIT(::SetLastError(currentError)); //this function must not change active system error variable! @@ -92,22 +88,37 @@ std::wstring formatSystemError(const std::wstring& functionName, ErrorCode lastE if (buffer) //"don't trust nobody" { ZEN_ON_SCOPE_EXIT(::LocalFree(buffer)); - output += L" "; - output += buffer; + lastErrorMsg = buffer; } #elif defined ZEN_LINUX || defined ZEN_MAC ZEN_ON_SCOPE_EXIT(errno = currentError); - output += L" "; - output += utfCvrtTo(::strerror(lastError)); + lastErrorMsg = utfCvrtTo(::strerror(lastError)); #endif + + return formatSystemError(functionName, lastError, lastErrorMsg); +} + + +inline +std::wstring formatSystemError(const std::wstring& functionName, ErrorCode lastError, const std::wstring& lastErrorMsg) +{ + std::wstring output = replaceCpy(_("Error Code %x:"), L"%x", numberTo(lastError)); + + if (!lastErrorMsg.empty()) + { + output += L" "; + output += lastErrorMsg; + } + if (!endsWith(output, L" ")) //Windows messages seem to end with a blank... output += L" "; output += L"(" + functionName + L")"; return output; } + } #endif //SYS_ERROR_H_3284791347018951324534 -- cgit