jeudi 26 février 2015

std::system_error with GetLastError() [duplicate]


This question already has an answer here:




What is the correct way to throw an std::system_error with the error code returned by GetLastError()? This has been asked before, but the answers are all over the place. Googling shows the same disparity in what category to use.


Most answers point to std::system_category, but isn't that usable only with errno error codes (both standard and POSIX)? If so, this is clearly wrong as errno and windows error codes do clash (EDOM and ERROR_LOCK_VIOLATION for example, both being defined as 33).


The second alternative is to use std::generic_category. This SO question point in that direction as it seem to work for the OP, but it refers to Boost's implementation and not C++11's and the the person answering is adamant about using std::system_error. Also, isn't std::generic_category, well, generic? There doesn't seem to exist any kind of guarantee that std::generic_category will understand the WinAPI error code.


The third and last possibility is to create a custom category, which may be problematic due to the need to override default_error_condition() and equivalent().


Aucun commentaire:

Enregistrer un commentaire