diff options
author | Daniel Wilhelm <daniel@wili.li> | 2015-10-02 14:57:46 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2015-10-02 14:57:46 +0200 |
commit | ad4e3d2c55e75193c41356c23619f80add41db18 (patch) | |
tree | dd836d120f50e472106e04968ef8185c25e4242e /zen/file_error.h | |
parent | 7.4 (diff) | |
download | FreeFileSync-ad4e3d2c55e75193c41356c23619f80add41db18.tar.gz FreeFileSync-ad4e3d2c55e75193c41356c23619f80add41db18.tar.bz2 FreeFileSync-ad4e3d2c55e75193c41356c23619f80add41db18.zip |
7.5
Diffstat (limited to 'zen/file_error.h')
-rw-r--r-- | zen/file_error.h | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/zen/file_error.h b/zen/file_error.h index d8c6224c..7be52282 100644 --- a/zen/file_error.h +++ b/zen/file_error.h @@ -36,14 +36,23 @@ DEFINE_NEW_FILE_ERROR(ErrorFileLocked); DEFINE_NEW_FILE_ERROR(ErrorDifferentVolume); -//CAVEAT: evalulate global error code *before* "throw" statement which may overwrite error code -//due to a memory allocation before it creates the thrown instance! (e.g. affects MinGW + Win XP!!!) -template <class FE = FileError> inline -void throwFileError(const std::wstring& msg, const std::wstring& functionName, const ErrorCode ec) //throw FileError -{ - throw FE(msg, formatSystemError(functionName, ec)); -} +//CAVEAT: thread-local Win32 error code is easily overwritten => evaluate *before* making any (indirect) system calls: +//-> MinGW + Win XP: "throw" statement allocates memory to hold the exception object => error code is cleared +//-> VC 2015, Debug: std::wstring allocator internally calls ::FlsGetValue() => error code is cleared +#ifdef _MSC_VER +#define THROW_LAST_FILE_ERROR(msg, functionName) \ + do \ + { \ + const ErrorCode ecInternal = getLastError(); \ + throw FileError(msg, formatSystemError(functionName, ecInternal)); \ + \ + __pragma(warning(suppress: 4127)) /*"conditional expression is constant"*/ \ + } while (false) +#else //variant witout "__pragma": +#define THROW_LAST_FILE_ERROR(msg, functionName) \ + do { const ErrorCode ecInternal = getLastError(); throw FileError(msg, formatSystemError(functionName, ecInternal)); } while (false) +#endif //----------- facilitate usage of std::wstring for error messages -------------------- |